Listing all machines in a domain

D

Dirk Hagemann

Hello!

I need to get a list of all machines in a (Windows-)domain. So I used
as described in the ActiveState Python Documentation
win32net.NetServerEnum('',100,win32netcon.SV_TYPE_ALL,'domain-x') to
get this list from the PDC. But the result is only a list of all
machines which are logged-in. What I really need is a list of ALL
machines - taht means also the machines which belong to this domain,
but are logged-off (or simply switched-off).

A colleague did it in Perl with this code:
Win32::AdminMisc::GetMachines( $dc, UF_WORKSTATION_TRUST_ACCOUNT,
\%wkslist, "" );
This retrieves a whole list of the machines of a domain.
How can I do this in Python???

Thanks a lot for your response!

Dirk
 
C

Colin Brown

Dirk Hagemann said:
Hello!

I need to get a list of all machines in a (Windows-)domain.

Using wmi is a possibility (maybe Win32_GroupUser). Search
for my recent posting in c.l.p "Tip: Windows internals using wmi".

Colin Brown
PyNZ
 
T

Tim Golden

I need to get a list of all machines in a (Windows-)domain. So I used
as described in the ActiveState Python Documentation
win32net.NetServerEnum('',100,win32netcon.SV_TYPE_ALL,'domain-x') to
get this list from the PDC. But the result is only a list of all
machines which are logged-in. What I really need is a list of ALL
machines - taht means also the machines which belong to this domain,
but are logged-off (or simply switched-off).

I'm a little surprised to find that this call returns only machine
logged-on (and do you, by the way, mean "switched on" or really
"logged on" - ie with someone's username active on the machine?).
However, see if this thread from the Python win32 group is of any use
to you.

http://aspn.activestate.com/ASPN/Mail/Message/1785767

TJG
 
D

Dirk Hagemann

Tim Golden said:
(e-mail address removed) (Dirk Hagemann) wrote in message

I'm a little surprised to find that this call returns only machine
logged-on (and do you, by the way, mean "switched on" or really
"logged on" - ie with someone's username active on the machine?).
However, see if this thread from the Python win32 group is of any use
to you.

http://aspn.activestate.com/ASPN/Mail/Message/1785767

TJG


Thanks for the link! I tried this code once before, but I got an error
because of this
"WinNT:" in the code. But on tuesday I will try again.I don't know if I also
got machines which are only switched on - but that'spossible (I will test
this as well on tuesday. Now I start into myextra-long weekend - yet :) ).
Dirk
 
T

Tim Golden

Dirk Hagemann said:
Tim Golden said:
(e-mail address removed) (Dirk Hagemann) wrote in message
I need to get a list of all machines in a (Windows-)domain.

[...] see if this thread from the Python win32 group is of any use
to you.

http://aspn.activestate.com/ASPN/Mail/Message/1785767

TJG


Thanks for the link! I tried this code once before, but I got an error
because of this
"WinNT:" in the code. But on tuesday I will try again.I don't know if I also
got machines which are only switched on - but that'spossible (I will test
this as well on tuesday. Now I start into myextra-long weekend - yet :) ).
Dirk

Just in case it helps, there was a follow-up discussion which somehow
became detached from its thread:

http://aspn.activestate.com/ASPN/Mail/Message/Python-win32/1786718

although that doesn't address problems with WinNT: which should work,
I think, on anything from NT upwards (not on Win9x). We don't use AD
here, and it works on my Win2K machine.

TJG
 
T

Tim Howarth

I need to get a list of all machines in a (Windows-)domain.

If an Active Directory domain then you could use;


import win32com.client

def do_onecontainer(Container):
for oneobject in Container:
if oneobject.Class.lower()=='computer':
print oneobject.cn

if oneobject.Class.lower()=="organizationalunit" or \
oneobject.Class.lower()== "container":
do_onecontainer(oneobject)

startContainer=win32com.client.GetObject("LDAP://DC=mydomain,DC=local")

do_onecontainer(startContainer)
 
D

Dirk Hagemann

Tim Howarth said:
In message <[email protected]>


If an Active Directory domain then you could use;


import win32com.client

def do_onecontainer(Container):
for oneobject in Container:
if oneobject.Class.lower()=='computer':
print oneobject.cn

if oneobject.Class.lower()=="organizationalunit" or \
oneobject.Class.lower()== "container":
do_onecontainer(oneobject)

startContainer=win32com.client.GetObject("LDAP://DC=mydomain,DC=local")

do_onecontainer(startContainer)

No, thank you. It's not an AD-domain - that's what we are preparing...

Dirk
 
D

Dirk Hagemann

Dirk Hagemann said:
Tim Golden said:
(e-mail address removed) (Dirk Hagemann) wrote in message
I need to get a list of all machines in a (Windows-)domain.

[...] see if this thread from the Python win32 group is of any use
to you.

http://aspn.activestate.com/ASPN/Mail/Message/1785767

TJG


Thanks for the link! I tried this code once before, but I got an error
because of this
"WinNT:" in the code. But on tuesday I will try again.I don't know if I also
got machines which are only switched on - but that'spossible (I will test
this as well on tuesday. Now I start into myextra-long weekend - yet :) ).
Dirk

Just in case it helps, there was a follow-up discussion which somehow
became detached from its thread:

http://aspn.activestate.com/ASPN/Mail/Message/Python-win32/1786718

although that doesn't address problems with WinNT: which should work,
I think, on anything from NT upwards (not on Win9x). We don't use AD
here, and it works on my Win2K machine.

TJG

Thank you!!! That works :)
Now I can care about the coming up next problems... ;-)

Dirk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top