Jump to content

$ping question


 Share

Recommended Posts

pipe the output from ping.exe to your autoit script using std functions (or a temp file for that matter) and then parse it to get the ip adress with something like StringRegExp (or the other StringXXX functions)

atleast i think that is what you want, as in converting "www.autoitscript.com" to "64.111.104.70"

Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

pipe the output from ping.exe to your autoit script using std functions (or a temp file for that matter) and then parse it to get the ip adress with something like StringRegExp (or the other StringXXX functions)

atleast i think that is what you want, as in converting "www.autoitscript.com" to "64.111.104.70"

Thanks.. I found some examples and had to download the beta version. this is the code I put together. maybe someone can use it after they clean it up a little. i'm going to put clean it up and hoping to put a wise front end on it that automatically takes the workstation names in a text field.

#include <Constants.au3>
#include <File.au3>
#NoTrayIcon

$file = FileOpen("sms2k3clientrepair_systems.inf", 0)
; --------Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
If @error = -1 Then 
    MsgBox(0,"Process Complete", "Complete")
    ExitLoop
EndIf

    $ping = Ping( $line ,250)

Select

    Case $ping = 0 

;MsgBox(0,"here you go", "Error")

    _FileWriteLog("notfoundIPs.log",  $line & " not found")

    Case $Ping = 1

    $run = Run(@ComSpec & " /c ping " & $line, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

    While 1
        $line2 = StdoutRead($run)

    If @error = -1 Then ExitLoop

        If StringInStr($line2, "Reply from") Then

            $temp = $line2

            $temp = StringTrimLeft($temp,11)

            $temp = StringTrimRight($temp,2)

            ProcessClose("ping.exe")

;           MsgBox(0,"here you go", $temp)
    _FileWriteLog("foundIPs.log",  $line & " " & $temp)
    EndIf
Wend
EndSelect
Wend

Thanks again

Link to comment
Share on other sites

could you give a peice of that .inf file.

the inf file just has workstation names in it. i have wise open a text window to paste workstation names into, wise creates the inf file with all the workstation names, then calls the script to run the ping command. i think it was running to fast and not truncating all the ping data so i had to slow it down. it's been working well for now, but i'm still testing.

this is that the new script looks like after some cleanup

#include <Constants.au3>
#include <File.au3>
#NoTrayIcon

$file = FileOpen("sms2k3clientrepair_systems.inf", 0)

; --------Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
If @error = -1 Then ExitLoop

    $ping = Ping( $line ,250)

Select

    Case $ping = 0 


        _FileWriteLog(@TempDir & "\sms2k3clientrepair\SMS2K3ClientRepair.log", "Unable to ping " & $line & " - Ping Workstations")

    Case $Ping = 1

    $run = Run(@ComSpec & " /c ping " & $line, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

    While 1
        $line2 = StdoutRead($run)

    If @error = -1 Then ExitLoop

        If StringInStr($line2, "Reply from") Then
sleep(250)
            $temp = $line2

            $temp = StringTrimLeft($temp,11)

sleep(250)

            $temp = StringTrimRight($temp,2)
            
sleep(250)
            ProcessClose("ping.exe")
sleep(250)

    _FileWriteLog(@TempDir & "\sms2k3clientrepair\SMS2K3ClientSuccess.log", $line & "    " & $temp)

    EndIf
Wend
EndSelect
Wend

again i'm still testing it.

Link to comment
Share on other sites

how about this:

#include <File.au3>

Dim $h_file = FileOpen("sms2k3clientrepair_systems.inf", 0), $s_line, $s_line2, $i_run

While 1
    $s_line = FileReadLine($h_file)
    If @error = -1 Then ExitLoop

    $s_line2 = ''
    
    $i_run = Run(@ComSpec & " /c ping -n 1 -l 1 " & $s_line, @SystemDir, @SW_HIDE, 2)
    
    While Not @error
        $s_line2 &= StdoutRead ($i_run)
    WEnd
    
    $s_line2 = StringRegExp($s_line2, '((?:\d{1,3}\.){3}\d{1,3})', 1)
    
    If UBound($s_line2) Then
        _FileWriteLog(@TempDir & "\sms2k3clientrepair\SMS2K3ClientSuccess.log", $s_line & "  " & $s_line2[0])
    Else
        _FileWriteLog(@TempDir & "\sms2k3clientrepair\SMS2K3ClientRepair.log", "Unable to ping " & $s_line & " - Ping Workstations")
    EndIf
    
WEnd
Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

how about this:

#include <File.au3>

Dim $h_file = FileOpen("sms2k3clientrepair_systems.inf", 0), $s_line, $s_line2, $i_run

While 1
    $s_line = FileReadLine($h_file)
    If @error = -1 Then ExitLoop

    $s_line2 = ''
    
    $i_run = Run(@ComSpec & " /c ping -n 1 -l 1 " & $s_line, @SystemDir, @SW_HIDE, 2)
    
    While Not @error
        $s_line2 &= StdoutRead ($i_run)
    WEnd
    
    $s_line2 = StringRegExp($s_line2, '((?:\d{1,3}\.){3}\d{1,3})', 1)
    
    If UBound($s_line2) Then
        _FileWriteLog(@TempDir & "\sms2k3clientrepair\SMS2K3ClientSuccess.log", $s_line & "     " & $s_line2[0])
    Else
        _FileWriteLog(@TempDir & "\sms2k3clientrepair\SMS2K3ClientRepair.log", "Unable to ping " & $s_line & " - Ping Workstations")
    EndIf
    
WEnd
damn you make it seem so easy.... yes it works... i have to look up some of the command because i've never used them but i really appreciate your help...

can i send you a six pack or something... B)

Link to comment
Share on other sites

damn you make it seem so easy.... yes it works... i have to look up some of the command because i've never used them but i really appreciate your help...

can i send you a six pack or something... B)

ok.. so now i found an issue where the script will return the IP although its not online

the dos ping brings back the following information:

C:\>ping ngrl5284

Pinging ngrl5284.s3.xx.xxxxxx.com [162.87.73.157]with 32 bytes of data:

Request timed out.

Request timed out.

Request timed out.

Request timed out.

i'm assuming the script sees the 2nd line and pulls he IP out. How do it get it to pull fromt he 3rd line maybe?
Link to comment
Share on other sites

use if Ubound() = 3 Then

and change the last param of regexp to 3

it makes sure that there are the correct number of ip's that are found if evryting went correct.

#include <File.au3>

Dim $h_file = FileOpen("sms2k3clientrepair_systems.inf", 0), $s_line, $s_line2, $i_run

While 1
    $s_line = FileReadLine($h_file)
    If @error = -1 Then ExitLoop

    $s_line2 = ''
    
    $i_run = Run(@ComSpec & " /c ping -n 1 -l 1 " & $s_line, @SystemDir, @SW_HIDE, 2)
    
    While Not @error
        $s_line2 &= StdoutRead ($i_run)
    WEnd
    
    $s_line2 = StringRegExp($s_line2, '((?:\d{1,3}\.){3}\d{1,3})', 3)
    
    If UBound($s_line2) = 3 Then
        _FileWriteLog(@TempDir & "\sms2k3clientrepair\SMS2K3ClientSuccess.log", $s_line & "  " & $s_line2[0])
    Else
        _FileWriteLog(@TempDir & "\sms2k3clientrepair\SMS2K3ClientRepair.log", "Unable to ping " & $s_line & " - Ping Workstations")
    EndIf
    
WEnd
Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
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
 Share

  • Recently Browsing   0 members

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