Ping Another Computer
The Internet is a dynamic network where computers appear and drop out of sight without warning. One simple test an application can always perform to check if a computer is reachable is to send a ping message. Technically, a ping is the equivalent of asking another computer, "Are you there?" To get its answer, ping sends a special type of message over a low-level Internet protocol called ICMP (Internet Control Message Protocol).
Note
Need to find out if a computer is reachable over the Internet? With the new Ping class, you can make this simple request without a tangle of low-level socket code.
Sending a ping message using the classes found in the System.Net
namespaces is challenging and
requires dozens of low-level code statements that deal with raw sockets.
In .NET 2.0, there's a much simpler solution with the new Ping
class in the
System.Net.NetworkInformation
namespace.
How do I do that?
To ping a computer, you use the Ping( )
method of
the My.Computer.Network
object.
This approach gives you convenient access to the bare minimum ping
functionality. The Ping( )
method
returns True
or False
depending on whether it received a
response from the computer you're trying to contact.
Note
Windows includes a utility called ping.exe that you can use to ping other computers at the command line.
Example 6-3 uses this method in order to contact the web server at http://www.yahoo.com.
Example 6-3. Pinging a remote computer
Module PingTest Sub Main( ) Dim Success As Boolean ...
Get Visual Basic 2005: A Developer's Notebook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.