获取本机IP,返回字符串
public static String GetLocalIp() { String[] Ips = GetLocalIpAddress(); foreach (String ip in Ips) if (ip.StartsWith("10.80.")) return ip; foreach (String ip in Ips) if (ip.Contains(".")) return ip; return "127.0.0.1"; } public static String[] GetLocalIpAddress() { string hostName = Dns.GetHostName(); //获取主机名称 IPAddress[] addresses = Dns.GetHostAddresses(hostName); //解析主机IP地址 string[] IP = new string[addresses.Length]; //转换为字符串形式 for (int i = 0; i < addresses.Length; i++) IP[i] = addresses[i].ToString(); return IP; }
长风破浪会有时,直挂云帆济沧海!
可通过下方链接找到博主
https://www.cnblogs.com/judes/p/10875138.html