c# 获取本机ip
/// <summary> /// 取本机主机ip /// </summary> /// <returns></returns> public static string GetLocalIP() { try { string AddressIP = ""; IPAddress[] ips = Dns.GetHostEntry(Dns.GetHostName()).AddressList; foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList) { if (_IPAddress.AddressFamily.ToString() == "InterNetwork") { AddressIP = _IPAddress.ToString(); } } return AddressIP; } catch (Exception ex) { return ex.Message; } }