Ping from VB6

I have an application that needs access to an Internet website, which I need to distribute. I need to put together a tool to test that Internet access is permissible, and that a firewall is not blocking access.
Can I do this using ping? I want to use VB6 for the tool
If yes, how do I know if the ping was successful, i.e access was allowed / disallowed?
If no, what other method can I use?

This must be able to run on Windows 2000, XP & Vista
Who is Participating?
Ping utilises an Internet Protocol (IP) named ICMP.  Specifically, you send an ICMP Echo Request to the remote host and wait for an ICMP Echo Reply to come back.

When connecting to a website, you are utilising an IP named TCP.  My point was that if you want to see if the web server is reachable, you should check that it's reachable over the same protocol as you want to talk to it because the ICMP traffic might be allowed on the network and TCP traffic might not - or even the other way around.

Therefore it would seem logical that your application which connects to a website needs only to properly handle any errors arising from a lack of connectivity or an unreachable website.

What method does your application use to connect to the website?

Use this function, works fine!

Regards, Dennis

Public Function PingSilent(strComputer As String) As Integer
    Dim oPing As SWbemObjectSet
    Dim oStatus As SWbemObject
    Set oPing = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
       InstancesOf("Win32_PingStatus where address='" & strComputer & "'")
    For Each oStatus In oPing
        If IsNull(oStatus.StatusCode) Or oStatus.StatusCode <> 0 Then
            PingSilent = 0 'not reachable
            PingSilent = 1 'is alive
        End If
End Function

Open in new window


good morning!

I've been using this...
Might give it a try...

if TestPing(strComputer) = True then
       debug.print "Connected"
       debug.print "Disconnected"
end if

Function TestPing(sName)
      Dim cPingResults, oPingResult
      Set cPingResults = GetObject("winmgmts://./root/cimv2").ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" & sName & "'")
     For Each oPingResult In cPingResults
            If oPingResult.StatusCode = 0 Then
                  TestPing = True
                  TestPing = False
            End If

End Function

i hope i could give u idea...

How do you know if your security is working?

Protecting your business doesn’t have to mean sifting through endless alerts and notifications. With WatchGuard Total Security Suite, you can feel confident that your business is secure, meaning you can get back to the things that have been sitting on your to-do list.

Ping is not necessarily the ideal solution.  The application might be used in an environment where ICMP echos are able to traverse the network but HTTP traffic is not.

Therefore I'd recommend attempting to connect to the website and properly handling the various responses - some of which may be:
TCP connection request refused.
TCP connection TimedOut.
ICMP Net Unreachable.
ICMP Host Unreachable.

and of course a successful connection.
TimTDPAuthor Commented:
Hi jahboite

Can you elaborate further?
TimTDPAuthor Commented:
Protocol: HTTP
Port: 80
Yes, yes, but I mean what code does the application use to access the website?  Is it using the sockets API or something like URLDownloadToFile?
TimTDPAuthor Commented:
Hi jahboite

It uses URLDownloadToFile.
And is checking the return value from URLDownloadToFile (which is 0 on a successful start of download and non-zero otherwise) not sufficient for your needs?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.