Jump to content

Recommended Posts

Posted

Hi

When reading a file with 26 ip addresses it can take up to two minutes to complete.  Is there a way to make this faster?  Am I doing something wrong?

#include <Array.au3>
#include <AutoItConstants.au3>
#include <Timers.au3>
#include <Constants.au3>
#include <Inet.au3>

Local $IPList = @ScriptDir & "\IPList.txt", $LogFile = @ScriptDir & "\" & @MON & "" & @MDAY & "" & @YEAR & "_" & @HOUR & "_" & @MIN & "_LogFile.txt", $sIPs = FileReadToArray($IPList)

;_ArrayDisplay($sIPs) ;Debug

Local $StartTime = _Timer_Init()

If Not FileExists($IPList) Then
    MsgBox(48, "Error", "Missing the IPLIST.txt file : " & @CRLF & $IPList & @CRLF & @CRLF & "Please make sure it exist then run the script again.")
    Exit
EndIf

FileWriteLine($LogFile, @CRLF)
FileWriteLine($LogFile, @MON & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN & ":" & @SEC & " DNS Lookup Started" & @CRLF)

_NSLookup()

Func _NSLookup()
    For $i = 0 To UBound($sIPs) - 1
        TCPStartup()
        Local $aResult = _TCPIpToName($sIPs[$i], 0)
        If @error Then
            FileWriteLine($LogFile, $sIPs[$i] & "," & "does not exist." & @CRLF)
        Else
            FileWriteLine($LogFile, $sIPs[$i] & "," & $aResult & @CRLF)
        EndIf
    Next
EndFunc   ;==>_NSLookup

FileWriteLine($LogFile, @MON & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN & ":" & @SEC & " DNS Lookup Ended." & @CRLF)

Local $DiffTime = _Timer_Diff($StartTime)
Local $EndTime = $DiffTime / 60000
Local $sTime = StringTrimRight($EndTime, 12)
FileWriteLine($LogFile, @MON & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN & ":" & @SEC & " Total script runtime: " & $sTime & " Minutes.")

Exit

 

Posted

Try taking the TCPStartUp out of the loop, put it before the start of the For loop. Also, after the loop put a TCPShutdown function call to close it.

Func _NSLookup()
    TCPStartup()
    For $i = 0 To UBound($sIPs) - 1
        Local $aResult = _TCPIpToName($sIPs[$i], 0)
        If @error Then
            FileWriteLine($LogFile, $sIPs[$i] & "," & "does not exist." & @CRLF)
        Else
            FileWriteLine($LogFile, $sIPs[$i] & "," & $aResult & @CRLF)
        EndIf
    Next
    TCPShutdown()
EndFunc   ;==>_NSLookup

 

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 Gude
How 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

Posted (edited)
49 minutes ago, BrewManNH said:

Try taking the TCPStartUp out of the loop, put it before the start of the For loop. Also, after the loop put a TCPShutdown function call to close it.

Func _NSLookup()
    TCPStartup()
    For $i = 0 To UBound($sIPs) - 1
        Local $aResult = _TCPIpToName($sIPs[$i], 0)
        If @error Then
            FileWriteLine($LogFile, $sIPs[$i] & "," & "does not exist." & @CRLF)
        Else
            FileWriteLine($LogFile, $sIPs[$i] & "," & $aResult & @CRLF)
        EndIf
    Next
    TCPShutdown()
EndFunc   ;==>_NSLookup

 

Thanks @BrewManNH but that did not make any difference.  Ill try other options.

Edited by antmar904
Posted (edited)

Place a ping into the loop for example:

Func _NSLookup()
    TCPStartup()
    For $i = 0 To UBound($sIPs, 500) - 1
        If Ping($sIPs[$i]) = 0 Then ContinueLoop
        Local $aResult = _TCPIpToName($sIPs[$i], 0)
        If @error Then
            FileWriteLine($LogFile, $sIPs[$i] & "," & "does not exist." & @CRLF)
        Else
            FileWriteLine($LogFile, $sIPs[$i] & "," & $aResult & @CRLF)
        EndIf
    Next
    TCPShutdown()
EndFunc   ;==>_NSLookup

 

Edited by Subz
Added Ping ms
Posted

If neither of these help,then there's probably not a lot to do to speed it up. It's calling Microsoft DLLs to do the work, so it's a Microsoft issue at that point.

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 Gude
How 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

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
  • Recently Browsing   0 members

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