c#ping IP是否可通讯
1 static void Main(string[] args) 2 { 3 string host = "192.168.1.110"; 4 Ping p1 = new Ping(); 5 PingReply reply = p1.Send(host); //发送主机名或Ip地址 6 StringBuilder sbuilder; 7 if (reply.Status == IPStatus.Success) 8 { 9 sbuilder = new StringBuilder(); 10 sbuilder.AppendLine(string.Format("Address: {0} ", reply.Address.ToString())); 11 sbuilder.AppendLine(string.Format("RoundTrip time: {0} ", reply.RoundtripTime)); 12 sbuilder.AppendLine(string.Format("Time to live: {0} ", reply.Options.Ttl)); 13 sbuilder.AppendLine(string.Format("Don't fragment: {0} ", reply.Options.DontFragment)); 14 sbuilder.AppendLine(string.Format("Buffer size: {0} ", reply.Buffer.Length)); 15 Console.WriteLine(sbuilder.ToString()); 16 } 17 else if (reply.Status == IPStatus.TimedOut) 18 { 19 Console.WriteLine("超时"); 20 } 21 else 22 { 23 Console.WriteLine("失败"); 24 } 25 Console.ReadKey(); 26 }
posted on 2022-06-12 22:28 泰坦尼克号上的活龙虾 阅读(70) 评论(0) 收藏 举报