Restored from previous forum. Originally posted by Nessie.
Is there a command that will let me ping a remote server? I have tried the ping routine that I found elsewhere on the site, but find it difficult to understand. I basicaly only want to know if the remote server replies or not. Any help would be most appreciated !!!
Is there a ping command
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by tranquil.
Which server do you want to connect to?
Connect to it, if connection is successfull the server is still online.

Mike
Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
Which server do you want to connect to?
Connect to it, if connection is successfull the server is still online.
Mike
Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Rings.
viewtopic.php?t=1106
its not so difficult as it seems.....
Its a long way to the top if you wanna .....CodeGuru
viewtopic.php?t=1106
its not so difficult as it seems.....
Its a long way to the top if you wanna .....CodeGuru
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by tranquil.
Do it so:
Do it so:
Code: Select all
Structure HOSTENT
h_name.l
h_aliases.l
h_addrtype.w
h_length.w
h_addr_list.l
EndStructure
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
PokeB(@Dummy,A1)
PokeB(@Dummy+1,A2)
PokeB(@Dummy+2,A3)
PokeB(@Dummy+3,A4)
ProcedureReturn Dummy
EndIf
EndIf
EndIf
EndProcedure
Procedure ping(ip$)
; Get IP of Host
pHostinfo = gethostbyname_(ip$) ; Get IP from Hostname
If pHostinfo = 0 ; Successfull? 0 if not!
ping=-1 ; Return -1 couse resolve fails
Else ; Everything is okay right now....
CopyMemory (pHostinfo, hostinfo.HOSTENT, SizeOf(HOSTENT)) ; Copy the Datas to our Structure
If hostinfo\h_addrtype #AF_INET ; Successfull?
ping=-1 ; Not!
Else
ipAddress = PeekL(hostinfo\h_addr_list) ; Everything allright here, get the pointer to our IP Address
ip$=StrU(PeekB(ipAddress),0)+"."+StrU(PeekB(ipAddress+1),0) ; Form our IP Address here
ip$+"."+StrU(PeekB(ipAddress+2),0)+"."+StrU(PeekB(ipAddress+3),0) ; and here
EndIf
EndIf
If ping-1 ; Now we have our IP and we can ping...
strAdd.s=ip$ ; Our IP to ping for
#PING_TIMEOUT = 20000 ; Max. wait for replay time (Ping time out)
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
EndIf
EndProcedure
[/code)
after that you should use result=ping("IP")
Hope that is what you want, and hope it works. Couse I snipped this little part out of an older source. The Ping Routine is Based on Rings Source posted in this forum.
Cheers
Mike
Tranquilizer/ Secretly!
[url]http://www.secretly.de[/url]
Registred PureBasic User-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm