Sử dụng .Net Reflector on System.Runtime.Remoting.Channels.CoreChannel Tôi giải thích 2 phương thức dưới đây. GetMachineIp() được gọi khi thiết lập một HttpChannel để truy cập từ xa.System.Runtime.Remoting.Channels.CoreChannel.GetMachineIP() từ .NET Reflector - vui lòng giải thích
internal static string GetMachineIp()
{
if (s_MachineIp == null)
{
IPHostEntry hostEntry = Dns.GetHostEntry(GetMachineName());
AddressFamily addressFamily = Socket.SupportsIPv4 ?
AddressFamily.InterNetwork : AddressFamily.InterNetworkV6;
IPAddress machineAddress = GetMachineAddress(hostEntry, addressFamily);
if (machineAddress != null)
{
s_MachineIp = machineAddress.ToString();
}
if (s_MachineIp == null)
{
throw new ArgumentNullException("ip");
}
}
return s_MachineIp;
}
internal static string GetMachineName()
{
if (s_MachineName == null)
{
string hostName = GetHostName();
if (hostName != null)
{
IPHostEntry hostEntry = Dns.GetHostEntry(hostName);
if (hostEntry != null)
{
s_MachineName = hostEntry.HostName;
}
}
if (s_MachineName == null)
{
throw new ArgumentNullException("machine");
}
}
return s_MachineName;
}
Câu hỏi của tôi là lý do tại sao sẽ Dns.GetHostEntry() trong GetMachineIP() thất bại với SocketException "Không chủ như vậy được biết đến". GetMachineName() trả về thành công (cũng có một GetHostEntry). Điều này chỉ xảy ra trên một máy bị cô lập. Nó có thể là một cái gì đó để làm với đăng ký DNS không chính xác?