c#获取本地IP地址

  string ipc = "";
            string AddressIP = string.Empty;
            foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
            {
                if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
                {
                    AddressIP = _IPAddress.ToString();
                }
            }
            ipc = AddressIP;
            Console.WriteLine(ipc);
posted @ 2020-01-16 13:39  你只管努力  阅读(1595)  评论(0编辑  收藏  举报