using System;
using System.Net;
class MySocket
{
static void Main()
{
string IpAddressString = string.Empty;
Console.WriteLine("Enter an IP address (e.g., 131.247.2.211):");
IpAddressString = Console.ReadLine();
IPAddress hostIPAddress = IPAddress.Parse(IpAddressString);
IPHostEntry hostInfo = Dns.GetHostEntry(hostIPAddress);
Console.WriteLine("\nHost name of: {0} is: {1}", hostIPAddress, hostInfo.HostName);
}
}
我输入IP地址,然后得到以下信息:
未处理的异常:System.Net.Sockets.SocketException:没有此类主机 在System.Net.Dns.InternalGetHostByAddress(IPAddress 地址,布尔值includeIPv6)位于 System.Net.Dns.GetHostEntry(IPAddress地址)位于 MySocketLab.Main()
这是我的输入示例:
gethostname.exe
Enter an IP address (e.g., 131.247.2.211):
208.27.32.23
从在线资源上看,这是正确的。还有什么我需要做的吗?