gpt4 book ai didi

c# - GetHostEntry() 不再解析地址

转载 作者:太空狗 更新时间:2023-10-29 17:58:37 26 4
gpt4 key购买 nike

我最近从 .NET v3.5 切换到 v4.0 Client Profile,第一次运行 GetHostEntry() 时遇到问题。

          tcpClient.SocketInfo.SourceName = remoteMatcher.Host; // "88.255.126.48"
tcpClient.SocketInfo.SourcePort = remoteMatcher.Port; // 999

IPHostEntry ipEntry = Dns.GetHostEntry(tcpClient.SocketInfo.SourceName);

GetHostEntry() 导致异常:

WSANO_DATA 11004 Valid name, no data record of requested type. The requested name is valid and was found in the database, but it does not have the correct associated data being resolved for. The usual example for this is a host name-to-address translation attempt (using gethostbyname or WSAAsyncGetHostByName) which uses the DNS (Domain Name Server). An MX record is returned but no A record—indicating the host itself exists, but is not directly reachable.

我要重新启动机器,想在我失去一切之前问这个问题。

更新:

我的解决方法:

   // .NET Framework v4.0 bug?? 
IPAddress ip;
if (IPAddress.TryParse(tcpClient.SocketInfo.SourceName, out ip))
tcpClient.SocketInfo.SourceIP = tcpClient.SocketInfo.SourceName;
else
{
IPHostEntry ipEntry = Dns.GetHostEntry(tcpClient.SocketInfo.SourceName);
IPAddress[] addr = ipEntry.AddressList;
tcpClient.SocketInfo.SourceIP = addr[addr.Length - 1].ToString();
}

最佳答案

这是我试过的东西,我记得遇到过同样的问题随意使用我的例子来测试你的东西

** 我改用 IPHostEntry **

string[] host = (address.Split('@'));
string hostname = host[1];

IPHostEntry IPhst = Dns.Resolve(hostname);
IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25);
Socket s= new Socket(endPt.AddressFamily,
SocketType.Stream,ProtocolType.Tcp);
s.Connect(endPt);

或者当我用它来获取电子邮件地址的主机名时

        try
{
Response.Write("One");
string[] host = (txtEmailAddress.Text.Split('@'));
string hostname = host[1];
Response.Write(host);
IPHostEntry IPhst = Dns.Resolve(hostname);
IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25);
Socket s = new Socket(endPt.AddressFamily,
SocketType.Stream, ProtocolType.Tcp);
Response.Write(endPt);
s.Connect(endPt);
}
catch (SocketException se)
{
lblErrMsg.Text = se.Message.ToString();
PublicUtils.AddError("Error: " + se.Message + txtEmailAddress.Text);
txtEmailAddress.Focus();
return;
}

关于c# - GetHostEntry() 不再解析地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6856534/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com