fortypoundhead.com

Use VB6 to ping a remote computer

Posted On 2017-05-19 by VB6Boy
Keywords:
Tags: Visual Basic 6 Tutorial Networking 
Views: 42


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 7 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.162.91.86

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



Recent Forum Posts

Coding Archive?
dwirch posted on May 25, 2017 at about 12:38 in Site News

BWASL returns
dwirch posted on May 13, 2017 at about 15:24 in Site News

BWASL returns
dwirch posted on May 13, 2017 at about 8:46 in Site News

Job Spammer: Balashankar Bose Bose
dwirch posted on May 11, 2017 at about 10:05 in Spammers

Job Spammer: Bharti Jigyasi
dwirch posted on May 11, 2017 at about 7:58 in Spammers

List of Shady Characters
dwirch posted on April 25, 2017 at about 16:39 in Webmaster Stuff