Beispiel #1
0
 private void Worker()
 {
     for (int i = ipBegin; i < ipEnd; i++)
     {
         string ip = ipHeader + i;
         if (GeneralMethod.Ping(ip))
         {
             ips += ip + ";";
         }
     }
     finish = true;
 }
Beispiel #2
0
        public static string GetGatewayIP()
        {
            string strGateway = "";

            //获取所有网卡
            NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
            //遍历数组
            foreach (var netWork in nics)
            {
                //单个网卡的IP对象
                IPInterfaceProperties ip = netWork.GetIPProperties();

                //获取该IP对象的网关
                GatewayIPAddressInformationCollection gateways = ip.GatewayAddresses;
                foreach (var gateWay in gateways)
                {
                    //如果能够Ping通网关
                    if (GeneralMethod.Ping(gateWay.Address.ToString()))
                    {
                        //得到网关地址
                        strGateway = gateWay.Address.ToString();
                        //跳出循环
                        break;
                    }
                }

                //如果已经得到网关地址
                if (strGateway.Length > 0)
                {
                    //跳出循环
                    break;
                }
            }

            return(strGateway);
        }