Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Ping's time

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ping's time

    Based on subroutine, found on Vbnet

    Code:
       #Compile Exe
       #Register None
       #Dim All
    
       Type ICMP_ECHO_REPLY
          Address         As Long
          Status          As Long
          RoundTripTime   As Long
          DataSize        As Long
          DataPointer     As Long
          Options         As Double
          Dta             As Asciiz * 250
       End Type
    
       Declare Function inet_addr Lib "WSOCK32.DLL" Alias "inet_addr" (s As Asciiz) As Long
       Declare Function IcmpCreateFile Lib "Icmp.Dll" Alias "IcmpCreateFile" As Long
       Declare Function IcmpCloseHandle Lib "Icmp.Dll" Alias "IcmpCloseHandle" _
          (ByVal IcmpHandle As Long) As Long
       Declare Function IcmpSendEcho Lib "icmp.dll" Alias "IcmpSendEcho" _
          (ByVal IcmpHandle As Long, ByVal DestinationAddress As Long, _
          RequestData As Asciiz, ByVal RequestSize As Long, _
          ByVal RequestOptions As Long, ReplyBuffer As ICMP_ECHO_REPLY, _
          ByVal ReplySize As Long, ByVal TmOut As Long) As Long
    
       Function PingTime (Address As Asciiz, PingTimeOut As Long) As Long
          Dim ECHO As ICMP_ECHO_REPLY
          Dim PingR As Long, hPort As Long, dwAddress As Long
    
          dwAddress = inet_addr (Address)
          Function = -1: If dwAddress = -1 Then Exit Function
          hPort = IcmpCreateFile()
          ECHO.Dta = "Hello"
          If hPort Then IcmpSendEcho hPort, dwAddress, ECHO.Dta, Len(ECHO.Dta), _
             0, ECHO, Len(ECHO), PingTimeOut: IcmpCloseHandle hPort: _
             If ECHO.status = 0 Then Function = ECHO.RoundTripTime
       End Function
          
       Function PbMain
          Dim PingTm As Long
          PingTm = PingTime("193.124.133.14", 1000)
          If PingTm >= 0 Then MsgBox  "Ping time" + Str$(PingTm) + " ms" Else _
             MsgBox "Problems"
       End Function
Working...
X