Ping Host with LotusScript

The Ping LotusScript class allows you to pass in an IP address and return whether the ping was successful or not. The class is useful if you're using DominoPDF via HTTP and want to check availability before converting a URL.

The code below can be created in a script library or the declaration section of an agent.

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

Sample usage for calling the class is below.

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

Comments are closed.