Fox2 Posted January 31, 2008 Share Posted January 31, 2008 Func ReverseDNS($IP) $t = TimerInit() $dnsinfo = "?" $PingCmd = Run(@ComSpec & " /c ping -a -n 1 " & $IP, "C:\", @SW_HIDE, $STDOUT_CHILD) While TimerDiff($t) < 2000 $PingResponseText = StdoutRead($PingCmd) If @error Then ExitLoop $x1 = StringInStr($PingResponseText, "Pinging") $x2 = StringInStr($PingResponseText, "[") If $x1 > 0 Then If $x2 > 0 Then $dnsinfo = StringStripWS(StringMid($PingResponseText, $x1 + 8, $x2 - $x1 - 8),3) ExitLoop EndIf Sleep(20) WEnd Return $dnsinfo EndFunc For anyone who wants it Oddly there doesn't seem to be a copy of this lying round. Feel free to adapt and credit. Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted January 31, 2008 Share Posted January 31, 2008 Thanks this could actually come in handy some time Link to comment Share on other sites More sharing options...
Fox2 Posted February 1, 2008 Author Share Posted February 1, 2008 (edited) An update in case you're doing a lot of DNS lookup. This is a quick and dirty way to cache your searches so far and save doing a new command window and PING call for each one. It caches all confirmed hits in "^" separated chunks, and leaves all misses uncached to retry. (A PING that worked, has worked, but one that didn't may work next time) Initializing code: ; Initialize DNS lookup cache Global $DNS_IPCache = "^" Global $DNS_LookupCache = "^" Updated Func: expandcollapse popupFunc ReverseDNS($IP) ; Strip WS - needed for caching and for textual use $IP = StringStripWS($IP,3) ; cached? $x = StringInStr($DNS_IPCache,"^" & StringLeft($IP & " ",15) & "^") if $x > 0 Then $entrynum = ($x - 1) / 16 + 1 $lookupstart = StringInStr($DNS_LookupCache,"^",0,$entrynum) + 1 $lookupend = StringInStr($DNS_LookupCache,"^",0,$entrynum + 1) Return StringMid($DNS_LookupCache, $lookupstart, $lookupend - $lookupstart) EndIf $t = TimerInit() $dnsinfo = "?" $PingCmd = Run(@ComSpec & " /c ping -a -n 1 " & $IP, "C:\", @SW_HIDE, $STDOUT_CHILD) While TimerDiff($t) < 2000 $PingResponseText = StdoutRead($PingCmd) If @error Then ExitLoop $x1 = StringInStr($PingResponseText, "Pinging") $x2 = StringInStr($PingResponseText, "[") If $x1 > 0 Then If $x2 > 0 Then $dnsinfo = StringStripWS(StringMid($PingResponseText, $x1 + 8, $x2 - $x1 - 8),3) ; and add to cache, padded to allow entry number to be found $DNS_IPCache &= StringLeft($IP & " ",15) & "^" $DNS_LookupCache &= $dnsinfo & "^" ExitLoop EndIf Sleep(20) WEnd Return $dnsinfo EndFunc (minor fix posted!) Edited February 1, 2008 by Fox2 Link to comment Share on other sites More sharing options...
James Posted February 1, 2008 Share Posted February 1, 2008 Nice! Maybe you could make a GUI or output the results to a file? Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Fox2 Posted February 1, 2008 Author Share Posted February 1, 2008 (edited) Nice! Maybe you could make a GUI or output the results to a file? The caching method is optimized for speed. Searching an array for a text match is much slower than searching in one string for a text match. The strings you get look like this: $DNS_IPCache: ^IP^IP^...^IP^ Each IP is * padded * to 15 characters. So each (IP+separator) is guaranteed 16 chars. $DNS_LookupCache: ^DNSINFO^DNSINFO^...^DNSINFO^ There is no information on DNSINFO length, but they are ^ separated ("^" is not a valid character in reverse DNS information so far as I know) So if you find a match for ^IP^ at position 1, 33, (16n+1), you know the cached text is between the (1st and 2nd), (2nd and 3rd), (N+1) and (n+2) occurance of "^" in the lookup cache. A bit of StringinStr() and you're there. That's how it works. To make it convert the cache strings to an array, use StringSplit() to split both strings at the "^", ignore the first and last result (null), and remove padding with StringStripWS(). $IPList = StringSplit($DNS_IPCache,"^",1) $DNSList = StringSplit($DNS_LookupCache,"^",1) For $entry = 1 to $IPList[0] $IPList[$entry] = StringStripWS($IPList[$entry],3) Next If $IPList[0] <= 2 then no entries exist, otherwise valid entries start at $IPList[2] and the last entry is one less than $IPList[0]. Macthjing DNS info is in the other table. You can easily rework this to split them into one table with 2 dimensions, or a file. Edited February 1, 2008 by Fox2 Link to comment Share on other sites More sharing options...
DirtDBaK Posted February 2, 2008 Share Posted February 2, 2008 lol I have a Nvida card so I get this:I can't run cmd.exe at all with my laptop which sucks... [center][/center] Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted February 2, 2008 Share Posted February 2, 2008 lol I have a Nvida card so I get this:I can't run cmd.exe at all with my laptop which sucks...What in the hell does Nvidia graphics card have to do with command prompt? Link to comment Share on other sites More sharing options...
HeffeD Posted February 2, 2008 Share Posted February 2, 2008 lol I have a Nvida card so I get this:NTVDM is your NT DOS virtual machine process... It's part of Windows. Nothing to do with your graphics card... Link to comment Share on other sites More sharing options...
DirtDBaK Posted February 2, 2008 Share Posted February 2, 2008 Well let me put it this way it occured after I installed my Nvida card and same thing for my buddy on his desktop but if you take out the card, uninstall the drivers the cmd works again! And don't tell me 'Thats not possible' like every other person, becuase I'm damn sure it is the problem! And it sux lol [center][/center] Link to comment Share on other sites More sharing options...
HeffeD Posted February 3, 2008 Share Posted February 3, 2008 What card is it? I have a GeForce 7300LE and have no problems with command prompts. If you indeed think your graphics card is the problem, I think you should contact nVidia. Link to comment Share on other sites More sharing options...
DirtDBaK Posted February 3, 2008 Share Posted February 3, 2008 Well I have a new IBM laptop so I don't care about my old one, I don't know what my buddies card is but mine is NVIDA GeForce Go 6100 [center][/center] Link to comment Share on other sites More sharing options...
ptrex Posted February 3, 2008 Share Posted February 3, 2008 (edited) @DbakThis is Error you get is related to one of the corrupted files :CAUSE:This issue may occur if one or more of the following files are missing or damaged:· Config.nt· Autoexec.nt· Command.comMost probably because of installing software that has corrupted these.Simple resolution (as i remember for the old NT 4.0 days). Search your machine for Command.com to begin with and copy it the Winnt\system32 to start with. If it did not solve your problem. Do the same for Config.NT etc. Or download this Quickfix 16 Bit SubSystem QuickfixEnjoy !!ptrex Edited February 3, 2008 by ptrex 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...
DirtDBaK Posted February 3, 2008 Share Posted February 3, 2008 thanks ptrex very few people actually listen to me that my nvida card caused the problem [center][/center] Link to comment Share on other sites More sharing options...
Fabry Posted February 3, 2008 Share Posted February 3, 2008 ReverseDNS works only on english O.S., in Italian: "Esecuzione di Ping Namecomputer [192.168.1.1] con 32 byte dati:" A lan chat (Multilanguage)LanMuleFile transferTank gameTank 2 an online game[center]L'esperienza è il nome che tutti danno ai propri errori.Experience is the name everyone gives to their mistakes.Oscar Wilde[/center] Link to comment Share on other sites More sharing options...
HeffeD Posted February 3, 2008 Share Posted February 3, 2008 thanks ptrex very few people actually listen to me that my nvida card caused the problemMost probably because of installing software that has corrupted these. Link to comment Share on other sites More sharing options...
NELyon Posted February 3, 2008 Share Posted February 3, 2008 As in, installing the drivers could have corrupted it. Link to comment Share on other sites More sharing options...
rogdog Posted February 4, 2008 Share Posted February 4, 2008 Hi Fox2, I have been meaning to create a script for reverse DNS and you example script prompted me to have a play. Your script works well but I decided to create a script using the command 'NSLOOKUP' instead of 'PING' To me NSLOOKUP is neater than PING as it only sends the reverse DNS commands to the DNS server on the network. In comparison, the PING command sends a reverse DNS lookup to the DNS server and then Pings the IPaddress in question. This is extra traffic on the network which is not actually required. I also wanted to be able to do a RDNS lookup on a large list of IP addresses so I didn't really want to send these unnecessary pings. Having said all that, I can still see that using PING is good if you also want to check whether the device is currently active on the network (assuming it responds to pings !) Anyway Here is my Simple equivalent NSLOOKUP version of the FUNC CODEFunc _ReverseDNS($IP) $IP = StringStripWS($IP,3) $NSLookupCmd = Run(@ComSpec & " /c nslookup "& $IP, "C:\", @SW_HIDE, $STDOUT_CHILD+$STDERR_CHILD) $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 I have also written a GUI to test the FUNC CODE#include <GuiIPAddress.au3> $hGUI = GUICreate("RDNS",600,400) $idEdit=GUICtrlCreateEdit ("", 0,0,600,350,BitOR($ES_AUTOVSCROLL,$ES_READONLY,$WS_HSCROLL,$WS_VSCROLL)) GUICtrlSendMsg($idEdit, $EM_SetLimitText, 0, 0); Set Edit Text Buffer Size to unlimited ; Create GUI $idBTNStart=GUICtrlCreateButton ("START", 10,360,90,25) $idBTNStop=GUICtrlCreateButton ("STOP", 110,360,90,25) GUICtrlCreateLabel ("START IP", 220,366,50,25) GUICtrlCreateLabel ("END IP", 420,366,50,25) $hIPAddressStart = _GUICtrlIpAddress_Create($hGUI, 280, 360) $hIPAddressEnd = _GUICtrlIpAddress_Create($hGUI, 470, 360) $IPStart = IniRead("rdns.ini","IpRange","Start","0.0.0.0") $IPEnd = IniRead("rdns.ini","IpRange","End","0.0.0.0") _GUICtrlIpAddress_Set($hIPAddressStart, $IPStart) _GUICtrlIpAddress_Set($hIPAddressEnd, $IPEnd) GUISetState (@SW_SHOW) Do $Msg = GUIGetMsg() If $Msg = $idBTNStart Then $IPStart = _GUICtrlIpAddress_Get ($hIPAddressStart) $IPEnd = _GUICtrlIpAddress_Get ($hIPAddressEnd) $iIPStart = _IP2Number($IPStart) $iIPEnd = _IP2Number($IPEnd) For $iIP = $iIPStart to $iIPEnd $Msg = GUIGetMsg() If $Msg = $GUI_EVENT_CLOSE then _Exit() If $Msg = $idBTNStop then ExitLoop $sIP = _Number2IP($iIP) GUICtrlSetData($idEdit,$sIP &" = "& _ReverseDNS($sIP )&@crlf,1) Next EndIf Until $Msg = $GUI_EVENT_CLOSE _Exit() Func _ReverseDNS($IP) $IP = StringStripWS($IP,3) $NSLookupCmd = Run(@ComSpec & " /c nslookup "& $IP, "C:\", @SW_HIDE, $STDOUT_CHILD+$STDERR_CHILD) $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 Func _Number2IP($IPNumber) Local $IPString = "" For $index = 3 to 0 step -1 $X = Int($IPNumber/(256^$index)) $IPNumber = $IPNumber - $X*256^$index $IPString &= $X &"." Next Return StringTrimRight($IPString,1) EndFunc Func _IP2Number ($IP) $IPArray=StringSplit($IP,'.') $IPValue=($IPArray[1]*(256^3))+($IPArray[2]*(256^2))+($IPArray[3]*(256^1))+($IPArray[4]) Return $IPValue EndFunc Func _Exit() IniWrite("rdns.ini","IpRange","Start",$IPStart) IniWrite("rdns.ini","IpRange","End",$IPEnd) EndFunc 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