获取本设备IP地址
作者:互联网
获取本设备(Android、PC)IP地址
public string GetLocalIP() { try { string HostName = Dns.GetHostName(); //得到主机名 IPHostEntry IpEntry = Dns.GetHostEntry(HostName); for (int i = 0; i < IpEntry.AddressList.Length; i++) { //从IP地址列表中筛选出IPv4类型的IP地址 //AddressFamily.InterNetwork表示此IP为IPv4, //AddressFamily.InterNetworkV6表示此地址为IPv6类型 if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork) { return IpEntry.AddressList[i].ToString(); } } return ""; } catch (Exception ex) { return ""; } }
标签:return,获取,IpEntry,AddressList,Dns,IP地址,AddressFamily,设备 来源: https://www.cnblogs.com/sethnie/p/11335798.html