;; KixGenerated: 2009/09/25 06:48:27
Break On
@Kix ?
ReadValue('HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\devices', 'Fax') ?
Test('farkle')
Ping('127.0.0.1')
Function Test($Arg)
'Arg is ' $Arg ?
EndFunction
;;
;;======================================================================
;;
;;FUNCTION ping()
;;
;;ACTION ping - Pings a host
;;
;;AUTHOR Glenn Barnas
;;
;;VERSION 2.0 - 2007/10/20 - WHS version
;; 1.0 - based on KORG Ping UDF by Jochen Polster, enhanced to
;; return values and IP's
;;
;;SYNTAX ping(host, [Flag], [Wait])
;;
;;PARAMETERS host - name of host to ping
;; FLAG - if negative, returns IP Address
;; if >0, specifies number of tries (default is 1)
;; Wait - optional ping timeout value
;;
;;
;;REMARKS ERROR is set to 0 if success, 1 otherwise.
;;
;;RETURNS FLAG >= 0: returns 1 if host is reachable, 0 if not
;; FLAG < 0: Returns IP address if resolvable, 0.0.0.0 if not
;;
;;DEPENDENCIES OS Commands Ping & Find
;;
;;TESTED WITH NT4, W2K, WXP
;;
;;EXAMPLES Ping('hostname') ; returns Success/Failure
;; Ping('hostname',-1) ; returns IP Address
;
Function Ping($_Host, OPTIONAL $_Flag, OPTIONAL $_Wait)
Dim $_oExec ; WSH Object
Dim $_Tries ; # of times to ping
Dim $_Timeout ; Ping timeout value
Dim $_Response ; Response Flag
Dim $_Line ; Line returned from command string
Dim $_Cmd ; first part of command string
Dim $_Count ; current ping count
$_Flag = Val($_Flag) ; determine what to do
$_Wait = Val($_Wait) ;
$_Tries = 1 ; one ping
$_Timeout = 1000 ; 1 second timeout
; set timeout if Wait is non-zero
If $_Wait > 0
$_Timeout = $_Wait
EndIf
If $_FLAG > 0 ; Multiple pings - return on first reply
$_Tries = $_FLAG
EndIf
; Ping the host $_Tries times, but only until a response is received
$_Count = 0
; search for reply from host during PING
$_Cmd = '%COMSPEC% /c ping.exe -4 -n 1 -w ' + $_Timeout + ' ' + $_Host
If $_Flag < 0
$_Cmd = $_Cmd + ' | %SystemRoot%\System32\Find "Pinging"'
Else
$_Cmd = $_Cmd + ' | %SystemRoot%\System32\Find "Reply" | %SystemRoot%\System32\Find "TTL="'
EndIf
Do
'w'
$_oExec = CreateObject("WScript.Shell").Exec($_Cmd)
'x'
If Not VarType($_oExec)=9 $Ping = 'WScript.Shell Exec Unsupported' Exit 10 EndIf
'y'
$_Line = Split(Join(Split($_oExec.StdOut.ReadAll + $_oExec.StdErr.ReadAll,CHR(13)),''),CHR(10))[0]
'z'
$_Response = IIf($_Line, 1, 0)
If $_Response
$_Count = $_Tries
EndIf
$_Count = $_Count + 1
If $_Count < $_Tries Sleep 0.25 EndIf
Until $_Count >= $_Tries
; If FLAG >= 0, return success/failure - otherwise return IP address
If $_FLAG >= 0
$Ping = $_Response
Else
If Not $_Response
$Ping = '0.0.0.0'
Else
; In this mode we return the IP address - we should have the HOSTNAME
; handle the 'duh' factor for times when we get the IP address instead!
If InStr($_Line,'[') > 0
$Ping= Split(Join(Split($_Line,']',-1),'['), '[')[1]
Else
$Ping = Split(Split($_Line,' ',-1)[1], ':')[0]
EndIf
EndIf
EndIf
Exit Not $_Response ; set the error code
EndFunction