?
Solved

Ping from VB6

Posted on 2008-11-18
9
Medium Priority
?
630 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:TimTDP
9 Comments
 
LVL 1

Expert Comment

by:d3n
ID: 22988103
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
 
LVL 13

Expert Comment

by:game-master
ID: 22990899

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
 
LVL 12

Expert Comment

by:jahboite
ID: 22993343
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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

Author Comment

by:TimTDP
ID: 22993399
Hi jahboite

Can you elaborate further?
0
 
LVL 12

Accepted Solution

by:
jahboite earned 360 total points
ID: 22993579
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
 

Author Comment

by:TimTDP
ID: 22993608
Protocol: HTTP
Port: 80
0
 
LVL 12

Expert Comment

by:jahboite
ID: 22993675
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
 

Author Comment

by:TimTDP
ID: 23003617
Hi jahboite

It uses URLDownloadToFile.
0
 
LVL 12

Expert Comment

by:jahboite
ID: 23007098
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

Featured Post

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How does someone stay on the right and legal side of the hacking world?
Phishing emails are a popular malware delivery vehicle for attack.  While there are many ways for an attacker to increase the chances of success for their phishing emails, one of the most effective methods involves spoofing the message to appear to …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month13 days, 18 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question