In the programming process, sometimes it is necessary to determine whether the host is online, the easiest way is to use the Windows ping command to see if you can ping. See a lot of articles on the Internet, say using C # to call Windows Ping.exe, and then parse the returned string. I think this way is too troublesome, just make a simple judgment, do not want to get so trouble.
Check it out, C # specifically provides a ping class similar to the ping command under Windows:
Command space: System.Net.NetworkInformation;
How to use:
BOOL online = false; Whether to
ping ping online = new ping ();
Pingreply pingreply = ping. Send ("192.168.132.191");
if (Pingreply.status = = ipstatus.success)
{
online = true;
Console.WriteLine ("Currently online, has been ping.") ");
}
else
{
Console.WriteLine ("Not on line, Ping does not pass.") ");
}