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();
}
C#获取本地IP地址
最新推荐文章于 2023-12-20 21:20:48 发布