Code: Select all
EnableExplicit
; Send ICMP request to given IP
; RETURN: value in ms on success, -1 else
Procedure Ping(IPv4.l, TimeOut=1000)
Protected hFile = IcmpCreateFile_()
Protected Res
Protected *Out.ICMP_ECHO_REPLY = AllocateMemory(SizeOf(ICMP_ECHO_REPLY) + 32)
If IcmpSendEcho_(hFile, IPv4, "@Echo this stuff", 32, 0, *Out, MemorySize(*Out), TimeOut) And *Out\Status = 0
Res = *Out\RoundTripTime
Else
Res = -1
EndIf
IcmpCloseHandle_(hFile)
FreeMemory(*Out)
ProcedureReturn Res
EndProcedure
; ping google DNS server
Debug Ping(MakeIPAddress(8,8,8,8))