- /* 获取网关 */
- ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
- ManagementObjectCollection moc = mc.GetInstances();
- string gatw = "";
- foreach (ManagementObject mo in moc)
- {
- if (!(bool)mo["IPEnabled"])
- continue;
- string[] gateways = (string[])mo["DefaultIPGateway"];
- foreach (string gw in gateways)
- gatw += gw;
- //MessageBox.Show(gatw);
- break;
- }
- //return;
-
- /* 检查网络是否正常 */
// 引用系统库 using System.Net.NetworkInformation;
- Ping p = new Ping();
- PingReply pr = p.Send(gatw); //p.Send("192.168.1.1");
- if (pr.Status != IPStatus.Success)
- {
- MessageBox.Show("请检查网络");
- return;
- }