zakird / pyad

Python Active Directory Tools | *Not actively maintained*
http://zakird.github.io/pyad/
176 stars 72 forks source link

Error in fetching IPAddress of Computers attached in domain. #145

Open 0cirius0 opened 3 years ago

0cirius0 commented 3 years ago

Querying for IPv4Address attribute results in error.

from pyad import *
import json

q = adquery.ADQuery()

q.execute_query(
    attributes = ["ipv4address"],
    where_clause = "objectClass = '*'",
    base_dn = "CN=Computers, DC=lab01, DC=local"
)
data=q.get_results()
Traceback (most recent call last):
  File "C:\Users\Administrator\Documents\run.py", line 7, in <module>
    q.execute_query(
  File "c:\users\administrator\appdata\local\programs\python\python39\lib\site-packages\pyad\adquery.py", line 78, in execute_query
    self.__rs, self.__rc = command.Execute()
  File "<COMObject ADODB.Command>", line 2, in Execute
  File "c:\users\administrator\appdata\local\programs\python\python39\lib\site-packages\win32com\client\dynamic.py", line 314, in _ApplyTypes_
    result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Provider', 'Unspecified error', None, 1240640, -2147467259), None)

But if I use other attributes like "dnshostname" then it works.

moosearch commented 2 years ago

Computer objects in active directory do not have an IPv4Address attribute. The dnsHostname exists as one, as seen in the link below: https://docs.microsoft.com/en-us/windows/win32/adschema/a-dnshostname

IPv4Address attribute exists as an attribute from the Get-ADComputer powershell cmdlet, but I suspect that is grabbed from elsewhere and not from active directory itself.