C # Console program implementation check IP, Ping is normal

Source: Internet
Author: User

using System; using System.Net; using System.Net.NetworkInformation; class Program {      static void Main( string [] args)      {          int count = 4;          IPAddress addr = IPAddress.Parse( "220.181.111.86" );          Ping ping = new Ping();          long timeSum = 0;          int succCount = 0;          //发送          Console.WriteLine( "正在ping {0}" , addr);          for ( int i = 0; i < count; ++i)          {              PingReply pr = ping.Send(addr);              if (pr.Status == IPStatus.TimedOut)                  Console.WriteLine( "超时" );              else if (pr.Status == IPStatus.Success)              {                  Console.WriteLine( "延时:{0}毫秒" , pr.RoundtripTime);                  ++succCount;                  timeSum += pr.RoundtripTime;              }          }          if (timeSum != 0)              Console.WriteLine( "平均延时{0}毫秒,丢包率{1}%" , 1.0 * timeSum / succCount, (count - succCount) * 100.0 / count);          else              Console.WriteLine( "丢包率100%" );          return ;      } }

C # Console program implementation check IP, Ping is normal

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.