Die Klasse PING enhält die Funktion Ping(), der die zu überpr?fende Adresse als Zeichenkette in der Form “127.0.0.1” übergeben wird. Ist der Ping erfolgreich wird true zurückgegeben,ansonsten false.
Die Konstante TIMEOUT gibt an, wie viele Millisekunden ( DEFAULT = 500 ms ) die Funktion versuchen soll, den Zielrechner zu erreichen. Zum Testen der Funktion erstellen sie einen Button und kopieren sie den folgenden Code in den Click Event der Schaltfläche
Sub Click(Source As Button)
Dim IP As String
Dim Ping As New Ping
IP = "192.168.123.184"
Msgbox Ping.Ping ( IP )
End Sub
Code in Script Bibliothek oder die Deklaration Sektion eines Agenten oder Buttons kopieren
Private Const TIMEOUT = 500
Private Type ICMP_OPT
Replacement As Long
OptionsData As Long
End Type
Private Type ICMP_ECHO_REPLY
Address As Long
status As Long
RoundTripTime As Long
DataSize As Long
DataPointer As Long
Options As ICMP_OPT
Data As String * 250
End Type
Declare Private Function IcmpCreateFile Lib "icmp.dll" () As Long
Declare Private Function IcmpCloseHandle Lib "icmp.dll" (Byval IcmpHandle As Long) As Long
Declare Private Function IcmpSendEcho Lib "icmp.dll" (Byval IcmpHandle As Long, Byval DestinationAddress As Long, Byval RequestData As String, Byval RequestSize As Long, Byval RequestOptions As Long,ReplyBuffer As ICMP_ECHO_REPLY, Byval ReplySize As Long, Byval REPLY As Long) As Long
Declare Private Function inet_addr Lib "wsock32" (Byval s As String) As Long
Class Ping
Private ECHO As ICMP_ECHO_REPLY
Public Function Ping ( IP As String ) As Variant
Ping = False
If IcmpCreateFile() Then
Call IcmpSendEcho ( IcmpCreateFile(),inet_addr ( IP ), "", 0, 0, ECHO, Len ( ECHO ), TIMEOUT )
If ECHO.status = 0 Then
Ping = True
Call IcmpCloseHandle ( IcmpCreateFile() )
End If
End If
End Function
End Class
Wonderfull Script, it’s work really nice and I use it for monitoring a couple of domino server.
as an improvement, it should be nice to ping a server name!!