我一直在网上搜索Dns gethostbyname更改为gethostentry,并相应地修改代码,但为什么仍然不显示正常的ipv4地址?我的代码:
string GetHostIP()
{
String myHostName = System.Net.Dns.GetHostName();
// Find host by name
System.Net.IPHostEntry myiphost = System.Net.Dns.GetHostEntry(myHostName);
String ipstring = "";
foreach(System.Net.IPAddress myipadd in myiphost.AddressList)
{
ipstring = myipadd.ToString();
return ipstring;
}
return ipstring;
}
Run Code Online (Sandbox Code Playgroud)