C # Ping Simple to use

Source: Internet
Author: User
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.") ");
}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.