Page 1 of 1
Need a PING function
Posted: Fri Oct 28, 2016 10:13 am
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?
Re: Need a PING function
Posted: Fri Oct 28, 2016 8:08 pm
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
Re: Need a PING function
Posted: Fri Oct 28, 2016 8:19 pm
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
Re: Need a PING function
Posted: Sat Oct 29, 2016 4:04 am
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
Re: Need a PING function
Posted: Sat Oct 29, 2016 12:59 pm
by rdonnay
Thanks for all your suggestions.
I will give them a try and report my findings.