网络连接检测using System.Net.NetworkInformation; public bool CheckNetworkConnectivity(string host 8.8.8.8) { try { Ping ping new Ping(); PingReply reply ping.Send(host, 3000); return reply.Status IPStatus.Success; } catch { return false; } }DNS解析验证using System.Net; public bool VerifyDnsResolution(string domain google.com) { try { IPHostEntry entry Dns.GetHostEntry(domain); return entry.AddressList.Length 0; } catch { return false; } }本地网络配置检查using System.Net.NetworkInformation; public void CheckLocalNetworkConfig() { NetworkInterface[] interfaces NetworkInterface.GetAllNetworkInterfaces(); foreach (var ni in interfaces) { if (ni.OperationalStatus OperationalStatus.Up) { IPInterfaceProperties ipProps ni.GetIPProperties(); foreach (UnicastIPAddressInformation addr in ipProps.UnicastAddresses) { Console.WriteLine($Interface: {ni.Name}, IP: {addr.Address}); } foreach (GatewayIPAddressInformation gateway in ipProps.GatewayAddresses) { Console.WriteLine($Gateway: {gateway.Address}); } } } }路由追踪实现using System.Net.NetworkInformation; public void TraceRoute(string host, int maxHops 30) { Ping ping new Ping(); PingOptions options new PingOptions(1, true); for (int i 1; i maxHops; i) { options.Ttl i; PingReply reply ping.Send(host, 3000, new byte[32], options); Console.WriteLine($Hop {i}: {reply.Address} - {reply.Status}); if (reply.Status IPStatus.Success || reply.Status IPStatus.TtlExpired) break; } }端口连接测试using System.Net.Sockets; public bool TestPortConnection(string host, int port, int timeout 3000) { using (TcpClient client new TcpClient()) { try { var result client.BeginConnect(host, port, null, null); bool success result.AsyncWaitHandle.WaitOne(timeout); client.EndConnect(result); return success; } catch { return false; } } }网络接口状态监控using System.Net.NetworkInformation; public void MonitorNetworkInterfaces() { NetworkChange.NetworkAvailabilityChanged (sender, e) { Console.WriteLine($Network available: {e.IsAvailable}); }; NetworkChange.NetworkAddressChanged (sender, e) { Console.WriteLine(Network configuration changed); }; }网络吞吐量测试using System.Diagnostics; public double TestNetworkThroughput(string url, int testSizeMB 10) { Stopwatch sw new Stopwatch(); long bytesToDownload testSizeMB * 1024 * 1024; using (WebClient client new WebClient()) { sw.Start(); byte[] data client.DownloadData(url); sw.Stop(); double speed (bytesToDownload / (1024.0 * 1024.0)) / (sw.Elapsed.TotalSeconds); return speed; } }