WP7芒果 - 如何获取IP地址对于一个给定的主机名 [英] WP7 Mango - How to get an IP address for a given hostname
问题描述
我需要得到一个IP地址从一个DnsEndPoint一个给定的主机名,并将其转换为一个IPEndPoint。我将如何去这样做呢? WP7缺乏Dns.GetHostEntry功能,所以有没有办法做到这一点,而无需创建一个Socket,发送数据到主机,然后从主机接收ping和阅读RemoteEndPoint属性来获取主机的IP地址?
I need to get an IP address for a given hostname from a DnsEndPoint, and convert it to an IPEndPoint. How would I go about doing this? WP7 lacks a Dns.GetHostEntry function, so is there any way to do this without creating a Socket, sending data to the host, then receiving a ping from the host and reading the RemoteEndPoint property to get the IP address of the host?
推荐答案
尝试使用 DeviceNetworkInformation.ResolveHostNameAsync
在微软.Phone.Net.NetworkInformation
命名空间,就像这样:
Try using DeviceNetworkInformation.ResolveHostNameAsync
in the Microsoft.Phone.Net.NetworkInformation
namespace, like this:
public void DnsLookup(string hostname)
{
var endpoint = new DnsEndPoint(hostname, 0);
DeviceNetworkInformation.ResolveHostNameAsync(endpoint, OnNameResolved, null);
}
private void OnNameResolved(NameResolutionResult result)
{
IPEndPoint[] endpoints = result.IPEndPoints;
// Do something with your endpoints
}
这篇关于WP7芒果 - 如何获取IP地址对于一个给定的主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!