获取本机IPV4地址
private static string GetIP() { string ip = ""; System.Net.IPAddress[] addressList = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName()); var tmp = addressList.Where(x => x.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork); foreach (var ips in tmp) { ip = ips.ToString(); } return ip; }
该方法需要引用:
using System.Linq;
调用:
string ip = GetIP();