Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

November 01, 1997 12:00 AM

Building an Automated Mass Ping Utility

Windows IT Pro
InstantDoc ID #562
Rating: (1)
Downloads
562.zip

Monitor the availability of your network systems

[Editor's Note: VB Solutions is about using Visual Basic (VB) to build a variety of solutions to specific business problems. This column doesn't teach you how to write VB, but how to use VB as a tool to provide quick, easy-to-implement solutions that you can use right away.]

In this month's VB Solutions column, I'll show how you can use Visual Basic (VB) to build the Automated Mass Ping utility. You can use this utility to monitor your network systems and quickly identify available systems and systems you cannot contact. You can define a list of networked system names or IP addresses to Automated Mass Ping and specify a time interval for testing availability. Automated Mass Ping periodically wakes up and pings each of the networked systems and reports the results. Screen 1, page 200, presents the Ping Status tab of the Automated Mass Ping window, which appears when you execute the utility.

Using Automated Mass Ping is very easy. You simply click Start Ping on the Ping Status tab to start the timed ping process for the list of systems. To stop the automated ping process, you click Stop Ping. However, before you begin using Automated Mass Ping, you need to define the list of systems that you want to monitor and specify the ping interval on the Settings tab, as shown in Screen 2, page 200.

You can enter either TCP/IP host names or TCP/IP addresses in the text box at the top of the Settings tab, and then click Add to add the new entry to the list of systems to be pinged. If you want to ping a TCP/IP host by name, you must have an entry for that host in your system's HOSTS file, or you must be attached to a Domain Name System (DNS) server that has an entry for the target host name. If the systems that you are pinging connect across the Internet, you can use your Internet Service Provider's (ISP's) DNS server to resolve host names. To remove an entry from the list, you must select the entry and then click Remove. If you want to clear the entire list, you click Clear.

The Ping interval setting controls how often (in seconds) Automated Mass Ping will begin pinging the list of systems. In Screen 2, you can see that the Ping interval is set to 300 seconds, which means that Automated Mass Ping will begin pinging the list of systems at 5-minute intervals.

The Beep on Ping check box controls whether Automated Mass Ping will beep if an error occurs during the ping process. Selecting the check box turns on the beep; clearing the check box lets Automated Mass Ping function silently.

You can save the values on the Settings tab to the Registry by clicking Save Settings. If you save the settings, they will be automatically loaded the next time Automated Mass Ping starts. Otherwise, the settings persist only until the application ends.

Inside Automated Mass Ping
Now that you've seen how to use Automated Mass Ping, let's take a closer look at how to build this utility. At the heart of Automated Mass Ping is ping32.dll, a DLL that I built based on the ping.c sample Microsoft distributes as a part of its Winsock development sample. The original Win32 command-line version of ping.c operates from only a text-oriented command line. The original ping.c does not operate under program control, and it cannot return the ping information to another application. I converted this sample command-line utility to a DLL that any development environment that supports external DLLs (such as VB) can call. Converting the Microsoft example to a DLL lets you call the ping function from VB and return the results of the ping to the calling applications. (You can download ping32.dll and its source code with the code for Automated Mass Ping from the Windows NT Magazine Web site at http://www.winntmag.com.)

Before you can use the functions that an external DLL contains, you must declare the functions using a .bas or .cls module. Ping32.dll contains one function (ping), which is declared in the ping.bas file. The VB declaration for the ping function follows:

Declare Function ping _Lib "ping32.dll" _(ByValsHostName$, _ByVal sIPAddr$, _ByVal iDataLen%, _lPingTime&, _ByVal iTimeout%, _ByVal iVerbose%) As Integer

The first parameter of the ping function is a string that contains either the name or the IP address of the system to be pinged. The second parameter is a string that the ping function returns. This string contains the IP address of the pinged system and lets the calling program retrieve the IP address for a given TCP/IP host name. The third parameter specifies the size of the data packet sent with the ping. The maximum data length that ping32.dll allows is 1024 bytes. The fourth parameter, a long variable, returns the elapsed milliseconds the ping function required to execute. The fifth parameter contains the maximum time in milliseconds that the ping function will wait for a response for sent or received packets. The sixth parameter specifies the mode of operation for the ping function. If you set this parameter to True, ping32.dll will run in verbose mode, the mode that displays all ping results and errors in a message box. Setting the sixth parameter to False runs ping32.dll in silent mode, the mode that reports any ping results and errors in the ping function's return code and output parameters.

Pinging Away
Next, let's look at how to incorporate the ping function into the application. At the core of Automated Mass Ping is the Ping_List subroutine presented in Listing 1.

The Ping_List subroutine is the workhorse of the utility. Ping_List displays the progress of the ping process and the status of each ping, and calls the ping function. The first few lines of code in Listing 1 declare Ping_List's working variables. At callout A in Listing 1, the subroutine clears the List_PingStatus list of any old status entries. The subroutine then retrieves the number of items in the List_IP name list using the ListCount method; at B in Listing 1, you can see the code that loops through the items in the list. As soon as the subroutine reads an entry from the list, it adds the entry to the List_PingStatus list; the subroutine uses the List_PingStatus.ListIndex method to make the newly added item the current selection. The ListIndex method lets the list scroll as the subroutine adds each item, which keeps the current ping status in view.

Related Content:

ARTICLE TOOLS

Comments
  • Anonymous User
    7 years ago
    Mar 09, 2005

    Give me

  • Ahmed Fraz Mamoon
    8 years ago
    Mar 10, 2004

    Hi there, I really wanna appreciate the writer for writing such a useful code. I actually want the same thing being a network adming of a big network. And as have also done Graduation in Computer Sciences my boss wants me to write the code for such an application. And u know u have saved much of my time. Michael Otey Thank you very much.

    Regards,

  • John Mishefske
    9 years ago
    Nov 26, 2003

    There is a small error in the code behind the form when a ping fails -
    the printing of the IP address in the List_PingStatus box doesn't get
    formatted correctly. In the Ping_List procedure:

    iPingResults = ping(List_IP.List(i), sIP, 64, lPingTime, 2000, 0)
    If iPingResults = 0 Then
    iTemp = InStr(sIP, Chr$(0))
    List_PingStatus.AddItem " Reply from: " & Mid$(sIP, 1, iTemp - 1) & _
    " took: " & Str(lPingTime) & " ms"
    Else
    iTemp = InStr(sIP, Chr$(0)) ' <---- ADD THIS LINE **************
    'If SSCheck_Beep.Value = True Then Beep
    List_PingStatus.AddItem " Reply from: " & Mid$(sIP, 1, iTemp - 1) & _
    " FAILED! Return code: " & Str$(iPingResults)
    End If

  • David Ivory
    11 years ago
    May 23, 2001

    Is there a problem using the ping32.dll to ping by IP? When pinging by name the funcution executes fine. When I use it to ping by IP the response time is fine but the funciton takes up to 30 seconds to return? Similar slow results when running the massping.exe provided in the download.

  • Mike Matheny
    13 years ago
    Aug 10, 1999

    In Mike Otey’s November 1997 VB Solutions column about a timer routine, he set the timer interval to text_time.text * 1000. In the example in Screen 2, he shows an entry of 300, which means you are passing a value of 300,000 to the timer interval. I don’t know what version of VB he’s running (I’m, running Visual Basic—VB—5.0, Service Pack—SP 2), but the largest interval my timer control will take is 65535, which in 1/1000s of a second (the timer resolution) is a little over a minute. Is the 300 entry a misprint, or is it possible? I have seen numerous routines to make the timer extend past 1 minute. You usually set a variable for the number of minutes and then set the timer interval for 60000 (1 minute). When the timer fires, increment the minute variable. When it reaches the desired value, do the routine and disable the timer.
    —Mike Matheny



    You are absolutely right. The largest possible ping interval is 65 seconds. Thanks for pointing this error out. I will post the updated version of the Mass Ping Utility on the Windows NT Magazine Web site at http://www.winntmag.com.

    --Mike Otey

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.