
解决方法:
把Dns.Resolve()改成Dns.GetHostEntry()即可
C#通过域名查询IP的完整代码如下:
IPHostEntry hostEntry = Dns.GetHostEntry(strDomain); IPEndPoint ipEndPoint = new IPEndPoint(hostEntry.AddressList[0], 0); string ipAddress = ipEndPoint.Address.ToString(); MessageBox.Show("IP地址:"+ipAddress);
|