fortypoundhead.com

Use VB6 to ping a remote computer

Posted On 2017-05-19 by VB6Boy
Keywords:
Tags: VB6 Miscellaneous Tutorial Networking 
Views: 199


When your application makes connections to remote computers, it is usually a good idea to check to see if the remote machine is up and responding prior to attempting a connection to it. Pinging a machine is one way to do it.

Visual Basic 6 doesn't have a built in method to perform an ICMP echo request (ie, Ping). But thankfully, we can leverage the Windows API to make it happen. The following function takes an IP address as input, then returns a boolean success/fail depending on the results of the ping.

Option Explicit

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

Public Function SimplePing(sIPadr As String) As Boolean

    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
    lIPadr = inet_addr(sIPadr)
    SimplePing = (GetRTTAndHopCount(lIPadr, lHopsCount, lMaxHops, lRTT) = SUCCESS)
    
End Function

Sample usage:

ret = SimplePing("192.168.1.100")


About the Author

VB6Boy has posted a total of 13 articles.

 


Comments On This Post

No comments on this post yet!


Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.


Your IP address is:54.198.147.221

Before you can post, you need to prove you are human. If you log in, this test goes away.



Recent Forum Posts

New security implemented
dwirch posted on July 23, 2017 at about 6:58 in Site News

Fold Code Manager into main KB?
VB6Boy posted on July 22, 2017 at about 14:42 in Site News

Fold Code Manager into main KB?
dwirch posted on July 22, 2017 at about 14:41 in Site News

Fold Code Manager into main KB?
dwirch posted on July 21, 2017 at about 22:46 in Site News

Fold Code Manager into main KB?
dwirch posted on July 20, 2017 at about 7:55 in Site News

Job Spammer: Sam Mallon
dwirch posted on July 18, 2017 at about 18:36 in Spammers