可用于检测网络畅通情况
using System.Net;using System.Net.NetworkInformation; namespace PING{ class Program { static void Main(string[] args) { Console.WriteLine("请输入IP"); string str = Console.ReadLine(); Console.WriteLine(ping(str)); Console.ReadLine(); } public static bool ping(string ip) { Ping pingip = new Ping(); PingOptions options = new PingOptions(); options.DontFragment = true; string data = "Test Data"; byte[] bytes = Encoding.ASCII.GetBytes(data); int timeout = 1000; PingReply replay = pingip.Send(ip, timeout, bytes, options); if(replay.Status==IPStatus.Success) { return true; } else { return false; } } }}