0

I have one window active directory and I have connected my computer to active directory for accessing the computers which is connected.

I have written below python code For connecting,

import wmi
try:
    connection = wmi.WMI(ip, user=username, password=password)
    print "connection is establised"
    for users in connection.Win32_SystemUsers():
        print users
except:
    print "connection failed"

Above code is showing all users list but i don't know how to get computers list with wmi win32 class.

Now problem is I want computer list which is in active directory using python. Anyone help me.

or

I found another method for connecting, that is ldap but here same problem is occuring. i am not able to find or access computer list.

I have used below code for connecting and showing user list

l = ldap.initialize("ldap://192.168.1.40")
try:
    l.protocol_version = ldap.VERSION3
    l.set_option(ldap.OPT_REFERRALS, 0)

    bind = l.simple_bind_s("administrator@example.com", "example@123")

    base = "dc=example, dc=com"
    criteria = "(&(objectClass=user)(sAMAccountName=*))"
    attributes = ['displayName', 'company']
    result = l.search_s(base, ldap.SCOPE_SUBTREE, criteria, attributes)

    results = [entry for dn, entry in result if isinstance(entry, dict)]
    print results
finally:
    l.unbind()

Now how to get computer's list

Thanks in advance!

4

1 回答 1

2

如果要搜索计算机,为什么要搜索用户?

criteria = "(&(objectClass=user)(sAMAccountName=*))"

尝试这个:

criteria = "(&(objectClass=computer))"
于 2013-11-05T09:02:13.750 回答