[windows] PING
Posted: Wed Apr 10, 2002 8:12 pm
Code updated for 5.20+
Restored from previous forum. Originally posted by Rings.
I translated this small routine to PureBasic.Some of you find it usefull before trying and using some other network related networkfunctions.
A Result of 0 and below 20ms is okay,negatives are faults.
Its a long way to the top if you wanna .....CodeGuru
Restored from previous forum. Originally posted by Rings.
I translated this small routine to PureBasic.Some of you find it usefull before trying and using some other network related networkfunctions.
A Result of 0 and below 20ms is okay,negatives are faults.
Code: Select all
;
;
;Ping (c) 2002 by Siegfried Rings (known as the 'CodeGuru' )
;
;
Procedure lngNewAddress(strAdd.s)
sDummy.s=strAdd
Position = FindString(sDummy, ".",1)
If Position>0
A1=Val(Left(sDummy,Position-1))
sDummy=Right(Sdummy,Len(Sdummy)-Position)
Position = FindString(sDummy, ".",1)
If Position>0
A2=Val(Left(sDummy,Position-1))
sDummy=Right(Sdummy,Len(Sdummy)-Position)
Position = FindString(sDummy, ".",1)
If Position>0
A3=Val(Left(sDummy,Position-1))
sDummy=Right(Sdummy,Len(Sdummy)-Position)
A4=Val(sDummy)
Dummy.l=0
PokeA(@Dummy,A1)
PokeA(@Dummy+1,A2)
PokeA(@Dummy+2,A3)
PokeA(@Dummy+3,A4)
ProcedureReturn Dummy
EndIf
EndIf
EndIf
EndProcedure
Procedure Ping(strAdd.s)
#PING_TIMEOUT = 200
lngHPort.l
lngDAddress.l
strMessage.s
lngResult.l
ECHO.ICMP_ECHO_REPLY
strMessage = "Echo This."
lngDAddress = lngNewAddress(strAdd)
lngHPort = IcmpCreateFile_()
lngResult = IcmpSendEcho_(lngHPort, lngDAddress, @strMessage, Len(strMessage), 0,@ECHO,SizeOf(ICMP_ECHO_REPLY), #PING_TIMEOUT)
If lngResult = 0
PingResult = ECHO\Status * -1
Else
PingResult = ECHO\RoundTripTime
EndIf
lngResult = IcmpCloseHandle_(lngHPort)
ProcedureReturn PingResult
EndProcedure
MessageRequester("Info",Str(Ping("127.0.0.1")),0)