bbo*_*sak 5 c# ip dns windows-phone-7
我需要从DnsEndPoint获取给定主机名的IP地址,并将其转换为IPEndPoint.我该怎么做呢?WP7缺少Dns.GetHostEntry函数,所以有没有办法在不创建Socket的情况下执行此操作,将数据发送到主机,然后从主机接收ping并读取RemoteEndPoint属性以获取主机的IP地址?
尝试DeviceNetworkInformation.ResolveHostNameAsync在Microsoft.Phone.Net.NetworkInformation命名空间中使用,如下所示:
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
}
Run Code Online (Sandbox Code Playgroud)