Jump to content
Sign in to follow this  
User751139

Results not consistant

Recommended Posts

User751139

Hello everyone, with a help of a member of this forum (Polymath) I was able to get a little tool that scans the workstations at my work for their status via ping. Either offline or online and a count of how many are online / offline. 

The problem is that no matter what... the results are never consistent...Sometimes the results show that there are 90/100 terminals that are alive and 10 are offline/unreachable however when I manually ping these "dead" terminals they are in-fact alive. what is causing this issue? It's never consistent..in fact I've put a list of 100 terminals are are live but still i a false report. 

Any help would be much appreciate it!!!

Code: 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=My Scripts\favicon.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <file.au3>
#include <iNet.au3> ;   <---<

Local $aIPList, $count, $ms
$count = 0
If Not _FileReadToArray("Hostnames.txt", $aIPList) Then
    MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
    Exit
EndIf
For $x = 1 To $aIPList[0]
    $ms = Ping($aIPList[$x], 1000)
    If not $ms Then

         FileWriteLine("Hostnames_log.txt", $aIPList[$x] & " " & $Names[0] & " " &"==X== OFF LINE ")

        Else

        $Names = Device_Names($aIPList[$x]) ;   <---< $Names[0]= IPAddress ; $Names[1] = Hostname.domain ; $Names[2] = hostnameOnly
;         $Hname = StringSplit($Names[1], ".") ;  <---< $Hname[1] = hostnameOnly
        ; Format the FileWriteLine using above variables    ;  <---<

        FileWriteLine("Hostnames_log.txt", $aIPList[$x] & " " & $Names[0] & " " &"==>== ONLINE ")
        $count += 1
    EndIf
Next
FileWriteLine("Hostnames_log.txt", @CRLF & "Terminals Alive: " & $count & @CRLF & "Terminals dead or unreachable: " & $aIPList[0] - $count)

MsgBox(4096, "Live Checker", "Scan Complete! Log file will open in 5 seconds...", 5)

Run("notepad.exe Hostnames_log.txt")


; This Function accepts either an IPaddress or a Hostname and returns
; a 2 elements array element[0]=IPaddress element[1]=hostname.domain

Func Device_Names($Net_device) ; <---<
    Local $Net_Names[3]
    TCPStartup()
    If StringRegExp($Net_device, "^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$") Then
        $Net_Names[1] = _TCPIpToName($Net_device) ; Resolves IP adress to Hostname
        If @error Then $Net_Names[1] = "Hostname error"
        $Net_Names[0] = $Net_device
    ElseIf $Net_device <> "" Then
        $Net_Names[0] = TCPNameToIP($Net_device) ; Resolves Hostname to IP adress
        If @error Then $Net_Names[0] = "IP error"
        $Net_Names[1] = $Net_device
    EndIf
    TCPShutdown()

    Local $temp = StringSplit($Net_Names[1], ".")
    $Net_Names[2] = $temp[1]

    Return $Net_Names
EndFunc   ;==>Device_Names
Edited by User751139

Share this post


Link to post
Share on other sites
BrewManNH

Is the log file recreated every time you run the script? How are you determining that the script found those offline in your log file?


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

Share this post


Link to post
Share on other sites
User751139

Yes it's re-created if i delete the log file. If i leave it it'll just append to it on the next scan. It registers the terminal offline if it doesn't get a reply from ping.. 

For $x = 1 To $aIPList[0]
    $ms = Ping($aIPList[$x], 1000)
    If not $ms Then

         FileWriteLine("Hostnames_log.txt", $aIPList[$x] & " " & $Names[0] & " " & "OFFLINE ")

        Else
Edited by User751139

Share this post


Link to post
Share on other sites
User751139

I thought It might be the ping timer however I changed it from 1000 ms to 5000 ms it doesn't seem to make any difference...The scan still completes in a few seconds when it should be taking a good min or 2..

Share this post


Link to post
Share on other sites
Chimp

try to move the lines with TCPStartup() and TCPShutdown() from within the function to the main script before and after the ping loop to line 22 and line 37 and also the call to the function before the if statement (line25) like this:

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=My Scripts\favicon.ico
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <file.au3>
#include <iNet.au3> ;   <---<

Local $aIPList, $count, $ms
$count = 0
If Not _FileReadToArray("Hostnames.txt", $aIPList) Then
    MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
    Exit
EndIf
TCPStartup()
For $x = 1 To $aIPList[0]
    $ms = Ping($aIPList[$x], 1000)
    $Names = Device_Names($aIPList[$x]) ;   <---< $Names[0]= IPAddress ; $Names[1] = Hostname.domain ; $Names[2] = hostnameOnly

    If Not $ms Then

        FileWriteLine("Hostnames_log.txt", $aIPList[$x] & " " & $Names[0] & " " & "==X== OFF LINE ")

    Else

        FileWriteLine("Hostnames_log.txt", $aIPList[$x] & " " & $Names[0] & " " & "==>== ONLINE ")
        $count += 1
    EndIf
Next
TCPShutdown()
FileWriteLine("Hostnames_log.txt", @CRLF & "Terminals Alive: " & $count & @CRLF & "Terminals dead or unreachable: " & $aIPList[0] - $count)

MsgBox(4096, "Live Checker", "Scan Complete! Log file will open in 5 seconds...", 5)

Run("notepad.exe Hostnames_log.txt")

; This Function accepts either an IPaddress or a Hostname and returns
; a 2 elements array element[0]=IPaddress element[1]=hostname.domain

Func Device_Names($Net_device) ; <---<
    Local $Net_Names[3]
    ;   TCPStartup()
    If StringRegExp($Net_device, "^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$") Then
        $Net_Names[1] = _TCPIpToName($Net_device) ; Resolves IP adress to Hostname
        If @error Then $Net_Names[1] = "Hostname error"
        $Net_Names[0] = $Net_device
    ElseIf $Net_device <> "" Then
        $Net_Names[0] = TCPNameToIP($Net_device) ; Resolves Hostname to IP adress
        If @error Then $Net_Names[0] = "IP error"
        $Net_Names[1] = $Net_device
    EndIf
    ;   TCPShutdown()
    Local $temp = StringSplit($Net_Names[1], ".")
    $Net_Names[2] = $temp[1]

    Return $Net_Names
EndFunc   ;==>Device_Names

bye


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
BrewManNH

What does your Hostnames.txt contain, and are the lines formatted correctly for the Ping to work on them? I tried your script, after rewriting it so that I didn't get an undeclared variable error, and it worked ok for me as-is.


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

Share this post


Link to post
Share on other sites
User751139

All of a sudden the IP address to Hostname no longer works  :ermm:

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×