public static string GetLocalIp() { string hostname = Dns.GetHostName(); IPHostEntry localhost = Dns.GetHostEntry(hostname); if (localhost != null) { foreach (IPAddress item in localhost.AddressList) { //判断是否是内网IPv4地址 if (item.AddressFamily == AddressFamily.InterNetwork) { return item.MapToIPv4().ToString(); } } } return "127.0.0.1"; }