Need a PING function

This forum is for general support of Xbase++
Post Reply
Message
Author
User avatar
rdonnay
Site Admin
Posts: 4728
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Need a PING function

#1 Post by rdonnay »

For several years, I have been using the below code to ping addresses.

Code: Select all

RunShell("/C ping.exe -n 1 -w 1 &cLocalIPaddress2 >ping.txt",,.f.,.t.) 
This is in a customer application that talks to a piece of hardware containing 2 microprocessors, each bound to a different IP address.
We never know what the IP addresses will be because they are leased addresses.
This requires pinging every address on a subnet until we find the Rabbit microprocessors.

Sometimes this takes a long time because using Runshell is a slow process.
Has anyone found a better solution than the PING command?
The eXpress train is coming - and it has more cars.

Cliff Wiernik
Posts: 605
Joined: Thu Jan 28, 2010 9:11 pm
Location: Steven Point, Wisconsin USA
Contact:

Re: Need a PING function

#2 Post by Cliff Wiernik »

Does this win32api function work.

https://msdn.microsoft.com/en-us/librar ... S.85).aspx

Code: Select all

IcmpSendEcho function

The IcmpSendEcho function sends an IPv4 ICMP echo request and returns any echo response replies. The call returns when the time-out has expired or the reply buffer is filled.
Syntax
C++


DWORD IcmpSendEcho(
  _In_     HANDLE                 IcmpHandle,
  _In_     IPAddr                 DestinationAddress,
  _In_     LPVOID                 RequestData,
  _In_     WORD                   RequestSize,
  _In_opt_ PIP_OPTION_INFORMATION RequestOptions,
  _Out_    LPVOID                 ReplyBuffer,
  _In_     DWORD                  ReplySize,
  _In_     DWORD                  Timeout
);

Para

Cliff Wiernik
Posts: 605
Joined: Thu Jan 28, 2010 9:11 pm
Location: Steven Point, Wisconsin USA
Contact:

Re: Need a PING function

#3 Post by Cliff Wiernik »

Found this for VB, appears to be standard win32.dll function call setup.

Declaration:

Code: Select all

Private Declare Function GetRTTAndHopCount Lib "iphlpapi.dll" _
        (ByVal lDestIPAddr As Long, _
         ByRef lHopCount As Long, _
         ByVal lMaxHops As Long, _
         ByRef lRTT As Long) As Long
         
Private Declare Function inet_addr Lib "wsock32.dll" _
        (ByVal cp As String) As Long
Code

Code: Select all

Public Function SimplePing(sIPadr As String) As Boolean

    ' Based on an article on 'Codeguru' by 'Bill Nolde'
    ' Thx to this guy! It 's simple and great!

    ' Implemented for VB by G. Wirth, Ulm,  Germany
    ' Enjoy!
    
    Dim lIPadr      As Long
    Dim lHopsCount  As Long
    Dim lRTT        As Long
    Dim lMaxHops    As Long
    Dim lResult     As Long
    
    Const SUCCESS = 1
    
    lMaxHops = 20               ' should be enough ...
    
    lIPadr = inet_addr(sIPadr)
    
    SimplePing = (GetRTTAndHopCount(lIPadr, lHopsCount, lMaxHops, lRTT) = SUCCESS)
    
End Function

WernerSt
Posts: 18
Joined: Thu Jan 28, 2010 3:48 am
Contact:

Re: Need a PING function

#4 Post by WernerSt »

Roger,
I use this function to check the internet to my internet address for example. I think this dll performs a ping:

function isDBFIBU
return InternetCheckConnectionA( "HTTP://WWW.DBFIBU.DE" + c_NULL, 1, 0 ) > 0

DLLFUNCTION InternetCheckConnectionA(Url,dwFlags,nSize) using STDCALL from WININET.DLL

User avatar
rdonnay
Site Admin
Posts: 4728
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Need a PING function

#5 Post by rdonnay »

Thanks for all your suggestions.

I will give them a try and report my findings.
The eXpress train is coming - and it has more cars.

Post Reply