IvanCodin Posted October 26, 2017 Posted October 26, 2017 (edited) I can't seem to get the name to resolve to the IP when I use a file a the source. If I statically assign the dns name it works. If I read a file and then loop through each line it fails. I think I am missing something really simple in my logic but can't seem to figure it out. Can someone point out my logic error? Would appreciate it. #include <MsgBoxConstants.au3> #include <Inet.au3> #include <File.au3> $file = @ScriptDir & "\servers.txt" If FileExists ($file) Then $line = FileRead($file) ; TS MsgBox(0,'',$line) ; Show the file content Else MsgBox (0,"Error - File missing", "File was not in " & @ScriptDir) EndIf FileOpen($file, 0) ; Servers file is a listing of the server names you wish to lookup. IE: www.autoitscript.com ; TS MsgBox(0,"TS", "File Open successful") ; Start the TCP service. TCPStartup() ; Assign a Local variable the IP address of www.autoitscript.com. Local $sIPAddress = TCPNameToIP("www.autoitscript.com") MsgBox(0,"Resolved Name", "autoscript.com resolves to " & $sIPAddress) ;; <==== This one works! For $i = 1 to _FileCountLines($file) $find = FileReadLine($file, $i) ; TS msgbox(0,'','Line ' & $i & ' is ' & $find) Local $sIPAddressTo = TCPNameToIP($find) MsgBox(0,"DNS Name", "Name resolves to " & $sIPAddressTo) ;; <===== This one does not work! Next If @error Then MsgBox($MB_SYSTEMMODAL, "", "Error code: " & @error) Else ; Do nothing EndIf TCPShutdown() ; Close the TCP service. Edited October 26, 2017 by IvanCodin
RTFC Posted October 26, 2017 Posted October 26, 2017 Your file I/O is wrong. This works: #include <MsgBoxConstants.au3> #include <Inet.au3> #include <File.au3> $file = @ScriptDir & "\servers.txt" If FileExists ($file) Then $line = FileRead($file) Else MsgBox (0,"Error - File missing", "File was not in " & @ScriptDir) EndIf $filehandle=FileOpen($file, 0) ; Servers file is a listing of the server names you wish to lookup. IE: www.autoitscript.com ; Start the TCP service. TCPStartup() For $i = 1 to _FileCountLines($file) $find = FileReadLine($filehandle, $i) MsgBox(0,'','Line ' & $i & ' is ' & $find) Local $sIPAddressTo = TCPNameToIP($find) ; NB @error needs to be evaluated IMMEDIATELY; any subsequent function all will reset it!<<<<<< If @error Then MsgBox($MB_SYSTEMMODAL, "", "Error code: " & @error) MsgBox(0,"DNS Name", "Name resolves to " & $sIPAddressTo) ;; <===== This one does not work! Next FileClose($filehandle) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<< TCPShutdown() ; Close the TCP service. My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O
BrewManNH Posted October 26, 2017 Posted October 26, 2017 Try this, saves some time if reading a large file. #include <MsgBoxConstants.au3> #include <Inet.au3> #include <File.au3> $file = @ScriptDir & "\servers.txt" If FileExists($file) Then $line = FileRead($file) Else MsgBox(0, "Error - File missing", "File was not in " & @ScriptDir) EndIf $filehandle = FileOpen($file, 0) ; Servers file is a listing of the server names you wish to lookup. IE: www.autoitscript.com ; Start the TCP service. TCPStartup() Local $sIPAddressTo ; <<<<<<<<<<<<<<<< don't declare variables in a loop, time wasted While 1 ;~ For $i = 1 To _FileCountLines($file) _FileCountLines is time consuming and not necessary $find = FileReadLine($filehandle) If @error Then ExitLoop ; <<<<<<<<<<<<<<<<< EOF reached, stop reading the file MsgBox(0, '', 'Line ' & $i & ' is ' & $find) $sIPAddressTo = TCPNameToIP($find) ; NB @error needs to be evaluated IMMEDIATELY; any subsequent function all will reset it!<<<<<< If @error Then MsgBox($MB_SYSTEMMODAL, "", "Error code: " & @error) MsgBox(0, "DNS Name", "Name resolves to " & $sIPAddressTo) ;~ Next WEnd FileClose($filehandle) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<< TCPShutdown() ; Close the TCP service. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Moderators JLogan3o13 Posted October 26, 2017 Moderators Posted October 26, 2017 @BrewManNH did you intend to remove that If statement at the top? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
BrewManNH Posted October 26, 2017 Posted October 26, 2017 1 hour ago, JLogan3o13 said: did you intend to remove that If statement at the top? The FileExists line? No, I wasn't focusing on that part, but the check for the file should be in there in some form, otherwise you might try reading a file that isn't there. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Moderators JLogan3o13 Posted October 26, 2017 Moderators Posted October 26, 2017 Agreed, I just thought you may have missed removing his extra $line and FileRead statement "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
IvanCodin Posted October 27, 2017 Author Posted October 27, 2017 Thanks for the help and more importantly the explanation!! I ran a test against a file with 5 names and it works perfectly. However if I use a large list, I had 100 entries, I get a 11001 error. My research pointed the post Jos wrote on Nov 4, 2004 that tells me the error is 11001 IP_BUF_TOO_SMALL Buffer too small. I can't tell if it's an Autoit issue or an OS issue. How do I increase the buffer or accommodate for a bigger list?
IvanCodin Posted October 27, 2017 Author Posted October 27, 2017 (edited) Did some more research and it looks like the 11001 error is it is a windows displayed when the name cannot be resolved. Is there a way to display no name found rather the error? Every thing I try shows I have error in my syntax. If @error = 11011 Then MsgBox(0,"Name Resolution", "Name " & $find & " was not found") Else @error -1 Then MsgBox($MB_SYSTEMMODAL, "", "Error code: " & @error) EndIf Edited October 27, 2017 by IvanCodin
IvanCodin Posted October 27, 2017 Author Posted October 27, 2017 After a little sleep I went back at re-looked at the suggestions you gave me. The answer was already in your reply. It was my lack of understanding that was missing. It had not dawned on me the if @ error statement you added did exactly what I was looking for. As always you guys are awsome! BrewManNH thanks for the suggestion about using FileReadLine rather than FileCountLines.
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