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
TimTDPAsked:
Who is Participating?
 
jahboiteCommented:
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?
0
 
d3nCommented:
Hi!

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
        Else
            PingSilent = 1 'is alive
        End If
    Next
 
End Function

Open in new window

0
 
game-masterCommented:

good morning!

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

if TestPing(strComputer) = True then
       debug.print "Connected"
else
       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
            Else
                  TestPing = False
            End If
      Next

End Function

i hope i could give u idea...

game-master
0
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.

 
jahboiteCommented:
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.
0
 
TimTDPAuthor Commented:
Hi jahboite

Can you elaborate further?
0
 
TimTDPAuthor Commented:
Protocol: HTTP
Port: 80
0
 
jahboiteCommented:
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?
0
 
TimTDPAuthor Commented:
Hi jahboite

It uses URLDownloadToFile.
0
 
jahboiteCommented:
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?
0
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.