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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

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
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.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

TimTDPAuthor Commented:
Hi jahboite

Can you elaborate further?
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?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TimTDPAuthor Commented:
Protocol: HTTP
Port: 80
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?
TimTDPAuthor Commented:
Hi jahboite

It uses URLDownloadToFile.
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?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.