richietheprogrammer Posted July 25, 2012 Share Posted July 25, 2012 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 More sharing options...
gcue Posted July 25, 2012 Share Posted July 25, 2012 Success: Returns string containing IP address corresponding to the name. not array richietheprogrammer 1 Link to comment Share on other sites More sharing options...
richietheprogrammer Posted July 25, 2012 Author Share Posted July 25, 2012 Thank you for your reply. I understand it is not an array now, but I am trying to display an array with both the name and the corresponding IP next to each other. How can I do so? Link to comment Share on other sites More sharing options...
gcue Posted July 25, 2012 Share Posted July 25, 2012 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) richietheprogrammer 1 Link to comment Share on other sites More sharing options...
DicatoroftheUSA Posted July 25, 2012 Share Posted July 25, 2012 You might also want to take a look at my little script. Statism is violence, Taxation is theft. Autoit Wiki Link to comment Share on other sites More sharing options...
richietheprogrammer Posted July 25, 2012 Author Share Posted July 25, 2012 Not sure why it is taking a very long time. There are quite a few computers that it is working on, but it appears to be stuck somewhere Any fast way to do it? Link to comment Share on other sites More sharing options...
gcue Posted July 25, 2012 Share Posted July 25, 2012 (edited) 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 July 25, 2012 by gcue Link to comment Share on other sites More sharing options...
richietheprogrammer Posted July 25, 2012 Author Share Posted July 25, 2012 Yes I see the results now, Thank you! Each item is taking about 5 seconds, and I have a couple thousand results.. I actually do not need the OS, but how would the array change if we take that out? Sorry I am not very confident with arrays. Link to comment Share on other sites More sharing options...
gcue Posted July 25, 2012 Share Posted July 25, 2012 (edited) 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 July 25, 2012 by gcue richietheprogrammer 1 Link to comment Share on other sites More sharing options...
richietheprogrammer Posted July 25, 2012 Author Share Posted July 25, 2012 Hmm, I supposed there would be no way to make this happen in a reasonable amount of time. Well thank you for your help at any rate Link to comment Share on other sites More sharing options...
gcue Posted July 25, 2012 Share Posted July 25, 2012 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 More sharing options...
richietheprogrammer Posted July 25, 2012 Author Share Posted July 25, 2012 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 More sharing options...
gcue Posted July 25, 2012 Share Posted July 25, 2012 look at inputbox Link to comment Share on other sites More sharing options...
richietheprogrammer Posted July 25, 2012 Author Share Posted July 25, 2012 I am very familiar with inputbox and the process. However, I am not sure how I would store/search, maybe Reg Expressions? Link to comment Share on other sites More sharing options...
water Posted July 25, 2012 Share Posted July 25, 2012 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 2024-07-28 - Version 1.6.3.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 (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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now