C#获取本地IP地址
C#获取本地IP地址
public static string GetLocalIp() { IPAddress localIp=null; try { IPAddress[] ipArray; ipArray=Dns.GetHostAddress(Dns.GetHostName()); localIp=ipArray.Frist(ip=>ip.AddressFamily==AddressFamily.InterNetwork); } catch(Exception ex) { } if(localIp==null) { localIp=IPAddress.Parse("127.0.0.1"); } return localIp.ToString(); }