rogdog Posted June 11, 2008 Share Posted June 11, 2008 (edited) Please find a small Func and test utiltiy for doing reverse DNS lookups on a networkHere is some history behind the FUNCI recently had a requirement at work incorporate a reverse dns lookup scanner into one of my Autoit programs.My first attempt was to use the UDF Function _TCPIpToName(ipaddress). This would work fine if there was a valid reply from the network but would take aprox 4.5 seconds per ip address if the FUNC timed out. This was way to slow as I had hundreds of potential ip addresses to scan. I needed to find a better way.Looking through the forums I found a useful post (http://www.autoitscript.com/forum/index.php?showtopic=63353) by forum member Fox2. This FUNC used the Windows command prompt PING utility and with a little tweaking, I managed to get the timeout to be much shorter than the UDF func above. This prompted me to experiment a bit further and I eventually managed to write a simillar function using the windows command prompt tool NSLOOKUP. The NSLOOKUP tool doesn't need to PING the network devices before resolving the names so it is quicker and produces less network traffic. Also, not all network devices are Pingable so NSLOOKUP should have a better hit rate.Anyway, here is my simple _ReverseDNS Func using NSLOOKUPNew Version: Posted 8th August 2012Added StderrRead command as suggested in Knollo's code (post #6)Func _ReverseDNS($IPAddress) Local $NSLookupCmd,$ResponseText,$X1,$X2 $IPAddress = StringStripWS($IPAddress,3) $NSLookupCmd = Run(@ComSpec & " /c nslookup "& $IPAddress, "", @SW_HIDE, $STDOUT_CHILD+$STDERR_CHILD) While 1 StderrRead($NSLookupCmd) If @error Then ExitLoop WEnd $ResponseText = StdoutRead($NSLookupCmd) If @error Then Return $x1 = StringInStr($ResponseText, "Name:") $x2 = StringInStr($ResponseText, "Address",0,-1) If $x1 > 0 and $x2 > 0 Then Return StringStripWS(StringMid($ResponseText, $x1 + 6, $x2 - $x1 - 6),3) Return "Unknown" EndFunc Edited August 8, 2012 by rogdog SamsonSlice and Parsix 1 1 My Scripts[topic="73325"]_ReverseDNS()[/topic]Favourite scripts by other members[topic="81687"]SNMP udf[/topic][topic="70759"]Using SNMP - MIB protocol[/topic][topic="39050"]_SplitMon:Section off your monitor!, split your monitor into sections for easy management[/topic][topic="73425"]ZIP.au3 UDF in pure AutoIt[/topic][topic="10534"]WMI ScriptOMatic tool for AutoIt[/topic][topic="51103"]Resources UDF embed/use any data/files into/from AutoIt compiled EXE files[/topic] Link to comment Share on other sites More sharing options...
taurus905 Posted June 12, 2008 Share Posted June 12, 2008 Hello rogdog, I wanted to thank you for writing and sharing your _ReverseDNS function and the example gui. I was going to write something very similar this evening. I did a search in the forum for "nslookup" and found your thread. I needed my script for tomorrow morning, so you can imagine how happy I was not to have to spend my evening writing what you had already completed. Now I can eat and get to bed at a decent hour. Thanks again for exhibiting the kind of unselfishness that makes AutoIt the best scripting language anywhere. I am sure other good people of this forum will also share their ideas in order to spark even more useful ideas for future scripting tasks. I also appreciated how you posted an example gui which quickly and easily demonstrated how the function worked without too much trouble. I too maintain a large number of servers and would love to know what other scripting ideas you have explored. I have written a Powershell script that uses WMI and an AutoIt gui. But I have encountered some problems with WMI which re-registering the DLLs in the wbem directory did not always solve, so I am looking for more reliable simple methods. Back to basics. Command-line stuff. Thanks again and keep up the good work. taurus905 "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs Link to comment Share on other sites More sharing options...
rogdog Posted June 12, 2008 Author Share Posted June 12, 2008 Thank you for your kind words. It is very rewarding when people go out of there way to thank others for there efforts.I am glad you found my scripts useful. I am using the _RevserseDNS() func everyday in an scheduled script that I have for gathering various information form my network. Some of the smallest functions can be the most useful !.My scheduled script mainly uses SNMP rather than WMI to scan network devices (switches,routers,etc) rather than servers. I run the script once a day to determine what nodes (servers,printers,etc) are connected to the network. I saw a bit of wmi code the other day which may help you posted by ptrexhttp://www.autoitscript.com/forum/index.php?showtopic=70759 My Scripts[topic="73325"]_ReverseDNS()[/topic]Favourite scripts by other members[topic="81687"]SNMP udf[/topic][topic="70759"]Using SNMP - MIB protocol[/topic][topic="39050"]_SplitMon:Section off your monitor!, split your monitor into sections for easy management[/topic][topic="73425"]ZIP.au3 UDF in pure AutoIt[/topic][topic="10534"]WMI ScriptOMatic tool for AutoIt[/topic][topic="51103"]Resources UDF embed/use any data/files into/from AutoIt compiled EXE files[/topic] Link to comment Share on other sites More sharing options...
ptrex Posted June 13, 2008 Share Posted June 13, 2008 @taurus905I have written a Powershell script that uses WMI and an AutoIt gui.I am interested to see how you did that.regardsptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
pegaze01 Posted April 25, 2012 Share Posted April 25, 2012 (edited) Hello rogdog I am interesting to have a look on your code but it seems to have problems or it is coded on your original post Is it a way to protect it or a server trouble. Any other way to read it ? regards Edited April 25, 2012 by pegaze01 Link to comment Share on other sites More sharing options...
knollo Posted July 2, 2012 Share Posted July 2, 2012 (edited) i know this post is some days old, the code above will not work in all cases because the io stream isnt treated right. this one is working better #include <Constants.au3> Func _nslookup($ip) Local $nsl_string_content[2],$RG=0,$LG=0,$nsl="" Local $nsl_string=Run(@ComSpec & " /c nslookup "&$ip, "", @SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD) while 1 $nsl_string_err=StderrRead($nsl_string) if @error Then ExitLoop WEnd While 1 $nsl_string_content[0]=StdoutRead($nsl_string) if @error or $nsl_string_content[0]="" Then ExitLoop $nsl_string_content[1]=$nsl_string_content[0] WEnd $LG=StringInStr($nsl_string_content[1],"Name:",1,1) $RG=StringInStr($nsl_string_content[1],Chr(13),1,1,$LG+5) If $LG>0 and $RG>0 then $nsl=StringStripCR(StringStripWS(StringMid($nsl_string_content[1],$LG+5,$RG-$LG-5),8)) EndIf Return $nsl EndFunc Edited September 4, 2012 by knollo Parsix 1 Link to comment Share on other sites More sharing options...
rogdog Posted August 8, 2012 Author Share Posted August 8, 2012 Hello rogdogI am interesting to have a look on your code but it seems to have problems or it is coded on your original postIs it a way to protect it or a server trouble.Any other way to read it ?regardsThis has now been fixed. For some reason my code in the OP had been corrupted !! Parsix 1 My Scripts[topic="73325"]_ReverseDNS()[/topic]Favourite scripts by other members[topic="81687"]SNMP udf[/topic][topic="70759"]Using SNMP - MIB protocol[/topic][topic="39050"]_SplitMon:Section off your monitor!, split your monitor into sections for easy management[/topic][topic="73425"]ZIP.au3 UDF in pure AutoIt[/topic][topic="10534"]WMI ScriptOMatic tool for AutoIt[/topic][topic="51103"]Resources UDF embed/use any data/files into/from AutoIt compiled EXE files[/topic] 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