Пример #1
0
        public static string GetLocalIP()
        {
            //本机IP地址
            string strLocalIP = "";
            //得到计算机名
            string strPcName = Dns.GetHostName();
            //得到本机IP地址数组
            IPHostEntry ipEntry = Dns.GetHostEntry(strPcName);

            //遍历数组
            foreach (var IPadd in ipEntry.AddressList)
            {
                //判断当前字符串是否为正确IP地址
                if (IsRightIP(IPadd.ToString()))
                {
                    //得到本地IP地址
                    strLocalIP = IPadd.ToString();
                    //结束循环
                    break;
                }
            }

            //返回本地IP地址
            return(strLocalIP);
        }
Пример #2
0
        public static string getIPAddress()
        {
            string      strLocalIp  = string.Empty;
            string      strPcName   = Dns.GetHostName();
            IPHostEntry iPHostEntry = Dns.GetHostEntry(strPcName);

            foreach (var IPadd in iPHostEntry.AddressList)
            {
                strLocalIp += string.Format("{0};", IPadd.ToString());
            }

            return(strLocalIp);
        }
Пример #3
0
        /// <summary>
        /// 得到执行统一下单接口的服务器的ip地址
        /// </summary>
        /// <returns></returns>
        public static string GetLocalIP()
        {
            string strLocalIP = null;
            //得到计算机名
            //string strPcName = Dns.GetYKstName();
            IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName());

            foreach (var IPadd in ipEntry.AddressList)
            {
                //得到本地IP地址
                strLocalIP = IPadd.ToString();
            }
            return(strLocalIP);
        }
Пример #4
0
        /// <summary>
        /// 得到本机IP
        /// </summary>
        public static string GetLocalIP()
        {
            string      strLocalIP = "";
            string      strPcName  = Dns.GetHostName();
            IPHostEntry ipEntry    = Dns.GetHostEntry(strPcName);

            foreach (var IPadd in ipEntry.AddressList)
            {
                if (IsRightIP(IPadd.ToString()))
                {
                    strLocalIP = IPadd.ToString();
                    break;
                }
            }
            return(strLocalIP);
        }
Пример #5
0
        public List <String> getAdapterIPs()
        {
            List <String> list = new List <String>();
            //得到计算机名
            string strPcName = Dns.GetHostName();
            //得到本机IP地址数组
            IPHostEntry ipEntry = Dns.GetHostEntry(strPcName);

            //遍历数组
            foreach (var IPadd in ipEntry.AddressList)
            {
                if (ValidateIPAddress(IPadd.ToString()))
                {
                    list.Add(IPadd.ToString());
                }
            }
            return(list);
        }
Пример #6
0
        //获取本机IP
        public string GetLocalIP()
        {
            //得到计算机名
            string strPcName = Dns.GetHostName();
            //得到本机IP地址数组
            IPHostEntry ipEntry = Dns.GetHostEntry(strPcName);

            //遍历数组
            foreach (var IPadd in ipEntry.AddressList)
            {
                //判断当前字符串是否为正确IP地址
                if (true)
                {
                    String netSegment = getLocaGateway().Substring(0, 7);
                    if (IPadd.ToString().Substring(0, 7).Equals(netSegment))
                    {
                        return(IPadd.ToString());
                    }
                }
            }

            return(null);
        }