GetHostEntry()不会再解析地址 [英] GetHostEntry() doesn't resolve the address anymore

查看:137
本文介绍了GetHostEntry()不会再解析地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近从.NET v3.5版本切换到V4.0客户端配置文件,并在第一次运行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

有效的名称,请求类型的数据记录。
请求的名称是有效的,在数据​​库中发现的,但它不具有正确的关联的数据被解析为。这样做的通常例子是主机名到地址转换尝试(使用gethostbyname或WSAAsyncGetHostByName),它使用DNS(域名服务器)。 MX记录返回,但主机本身没有A指示记录存在,但不是直接可达。




我要重新启动本机与想问前失去了我的脑海里所有的东西这个问题。



更新:



我的解决方法:

  //的.NET Framework 4.0版的bug? 
ip地址的IP;
如果(IPAddress.TryParse(tcpClient.SocketInfo.SourceName,出IP))
tcpClient.SocketInfo.SourceIP = tcpClient.SocketInfo.SourceName;
,否则
{
IPHostEntry ipEntry = Dns.GetHostEntry(tcpClient.SocketInfo.SourceName);
ip地址[]地址= ipEntry.AddressList;
tcpClient.SocketInfo.SourceIP =地址[addr.Length - 1]的ToString();
}


解决方案

在这里,我有话试过了,我记得运行到同样的问题
随意使用我的例子来测试你的东西。



**我用IPHostEntry代替**

 的String [] =主机(address.Split('@')); 
字符串主机=主机[1];

IPHostEntry IPhst = Dns.Resolve(主机名);
IPEndPoint endPt =新IPEndPoint(IPhst.AddressList [0],25);
插座S =新的Socket(endPt.AddressFamily,
SocketType.Stream,ProtocolType.Tcp);
s.Connect(endPt);


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

 
{
的Response.Write(1);
的String [] =主机(txtEmailAddress.Text.Split('@'));
字符串主机=主机[1];
的Response.Write(主机);
IPHostEntry IPhst = Dns.Resolve(主机名);
IPEndPoint endPt =新IPEndPoint(IPhst.AddressList [0],25);
插座S =新的Socket(endPt.AddressFamily,
SocketType.Stream,ProtocolType.Tcp);
的Response.Write(endPt);
s.Connect(endPt);
}
赶上(SocketException SE)
{
lblErrMsg.Text = se.Message.ToString();
PublicUtils.AddError(错误:+ se.Message + txtEmailAddress.Text);
txtEmailAddress.Focus();
的回报;
}


I recently switched from .NET v3.5 to v4.0 Client Profile and at first run GetHostEntry() got problem.

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

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

GetHostEntry() causes an exception:

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.

I'm gonna reboot the machine and wanted to ask this question before all things lost on my mind.

UPDATE:

My workaround:

   // .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();
   }

解决方案

here is something that I have tried, I recall running into the same problem feel free to use my example to test your stuff

** I used IPHostEntry instead **

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);

or when I used it to get hostname of email address

        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;
        }  

这篇关于GetHostEntry()不会再解析地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆