Jump to content

AD Get computer names + IP Addresses


Recommended Posts

Hello community, I am trying to retrieve computer names from AD and list their IP addresses. By searching the forum, and trying to come up with my code, below is what I have. It lists all the names properly, but I am unable to list their corresponding IP addresses. I am not sure if I am using TCPNameToIP correctly. Any help is greatly appreciated! :)

#include <ADfunctions.au3>

Global $aComputers2
$sOU = $strDNSDomain
_ADGetObjectsInOU($aComputers2,$sOU,"(objectclass=computer)",2,"name,operatingSystem")
Global $bak1
TCPStartup()
For $i = 1 to $aComputers2[0]
;Msgbox(0,"",$aComputers2[$i])
         $bak1 = TCPNameToIP($aComputers2[$i])
     Next
_ArrayDisplay($bak1)
Link to comment
Share on other sites

you can get ad.au3 from here

#include <AD.au3>

Global $aComputers2

_AD_Open()

If @error Then
    MsgBox(0, "", "unable to connect")
    Exit
EndIf

$aComputers2 = _AD_GetObjectsInOU("", "(objectclass=computer)", 2, "name,operatingSystem")

_AD_Close()

Local $results[1][1]

TCPStartup()

For $i = 1 To UBound($aComputers2) - 1
    $ip_address = TCPNameToIP($aComputers2[$i][0])

    ReDim $results[UBound($results) + 1][3]

    $results[UBound($results) - 1][0] = $aComputers2[$i][0]
    $results[UBound($results) - 1][1] = $aComputers2[$i][1]
    $results[UBound($results) - 1][2] = $ip_address
Next

TCPShutdown()

_ArrayDisplay($results)
Link to comment
Share on other sites

just the way its gonna work - do you need the OS? might be a little faster if you dont

code below shows results as it gets them (need to run uncompiled - using F5 in scite)

#include <AD.au3>

_AD_Open()

If @error Then
MsgBox(0, "", "unable to connect")
Exit
EndIf

$aComputers2 = _AD_GetObjectsInOU("", "(objectclass=computer)", 2, "name,operatingSystem")

_AD_Close()

Local $results[1][1]

TCPStartup()

For $i = 1 To UBound($aComputers2) - 1
$ip_address = TCPNameToIP($aComputers2[$i][0])

ReDim $results[UBound($results) + 1][3]

$results[UBound($results) - 1][0] = $aComputers2[$i][0]
$results[UBound($results) - 1][1] = $aComputers2[$i][1]
$results[UBound($results) - 1][2] = $ip_address

ConsoleWrite($aComputers2[$i][0] & @CRLF)
ConsoleWrite($aComputers2[$i][1] & @CRLF)
ConsoleWrite($ip_address & @CRLF)
ConsoleWrite(@CRLF)
Next

TCPShutdown()

_ArrayDisplay($results)
Edited by gcue
Link to comment
Share on other sites

actually doesnt seem to save too much time but here it is:

#include <AD.au3>

_AD_Open()

If @error Then
MsgBox(0, "", "unable to connect")
Exit
EndIf

$aComputers2 = _AD_GetObjectsInOU("", "(objectclass=computer)")

_AD_Close()

Local $results[1][1]

TCPStartup()

For $i = 1 To UBound($aComputers2) - 1
$ip_address = TCPNameToIP($aComputers2[$i])

ReDim $results[UBound($results) + 1][2]

$results[UBound($results) - 1][0] = $aComputers2[$i]
$results[UBound($results) - 1][1] = $ip_address

ConsoleWrite($aComputers2[$i] & @CRLF)
ConsoleWrite($ip_address & @CRLF)
ConsoleWrite(@CRLF)
Next

TCPShutdown()

_ArrayDisplay($results)
Edited by gcue
Link to comment
Share on other sites

dont think so, i think the way tcpnametoip works is that it does a lookup on your dns server - not sure if theres a way to do multiple at once

unfortunately - one at a time it looks like

Link to comment
Share on other sites

Fair enough. I do have another question, however, since this process is not going to be feasible. Using the AD library, is there anyway I can input the name (or part of the name) of a machine on the network, and have the script look it up and run a "tcpnametoip " and return the IP address? This method might be more feasible because it will only go through that function once. Any idea if that would be possible?

Link to comment
Share on other sites

If you only want to retrieve the name if a single computer use _AD_GetObjectAttribute.

$sComputer = InputBox(...)
$sName = _AD_GetObjectAttribute($sComputer & "$", "name")
"$" is needed because the samaccountname of a computer has a $ at the end.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...