i will sent ping via vb6.0 but not shell command
need what API for ping ? (example code)
somebody help me plzzz
thank you
Printable View
i will sent ping via vb6.0 but not shell command
need what API for ping ? (example code)
somebody help me plzzz
thank you
I'm not going to write all the code for this as it is verly clearly written already here:
IcmpSendEcho: Ping a Machine by IP Address
and here:
IcmpSendEcho: Ping a Machine by Host Name
It's sample is using 11 APIs but I'm pretty sure if you look at the code and only take what you need for yourself it will be shorter.
Good Luck :thumb:
You can ping using the IPHLP API... Let me create an example for you....
here it is
Code: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
Private Sub Command1_Click()
MsgBox PingIP("xxx.xxx.xxx.xxx")
End Sub
Public Function PingIP(sIPadr As String) As Boolean
Dim lIPadr As Long, lHopsCount As Long, lRTT As Long, lMaxHops As Long, lResult As Long
Const SUCCESS = 1
lMaxHops = 20
lIPadr = inet_addr(sIPadr)
PingIP = (GetRTTAndHopCount(lIPadr, lHopsCount, lMaxHops, lRTT) = SUCCESS)
End Function
Nice one koolsid, using that is short and sweet :thumb:
I tried to checkout a sample and came across an article implying a memory leak issue when using that API in C (see link for reference):
Memory leakage in Iphlpapi-Function GetRTTAndHopCount ?
To quote from the link:
I'm don't know if this is an issue too when using it from VB6, also this was a few years ago. Anyone know if it is an issue ?Quote:
I've rewritten it without MFC (which I find totally annoying), and there
seems to be a real leak in the call, yes. I'd say it's a bug to be reported
to product support services. I think I'm totally up-to-date with all the OS
QFEs, so this would require a new one. By the way, the leak is not always
8k. During the first five or six passes, the leak is sometimes 4k,
sometimes nothing, and sometimes 8k. After it's run for a while, it seems
to stabilize on 8k, though.
I won't be able to test it right now as I am in the office but if someone can test it using this...
SO thank
if your query is solved then do remember to mark this thread resolved ;)