如何在Windows Phone 8中将主机名解析为IP地址? [英] How to resolve a hostname to an IP address in Windows Phone 8?

查看:56
本文介绍了如何在Windows Phone 8中将主机名解析为IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,将输入 www.google.com 等主机名。如何获取Windows中的IP地址电话8?


请尽可能提供代码段



提前致谢。

解决方案

您可以使用类  DeviceNetworkInformation。 


试用此代码:

 private void ResolveHostName(String hostName)
{
var endPoint = new DnsEndPoint(hostName,80);
Microsoft.Phone.Net.NetworkInformation.DeviceNetworkInformation.ResolveHostNameAsync(endPoint,OnNameResolved,null);
}

private void OnNameResolved(Microsoft.Phone.Net.NetworkInformation.NameResolutionResult result)
{
IPEndPoint [] endpoints = result.IPEndPoints;
//这里你的地址如果解决了
if(endpoints!= null&& endpoints.Length> 0)
{
var ipAddress = endpoints [0] .Address ;
}
}


并使用它来调用ResolveHostName(" www.google.com");


In my app,hostname like www.google.com will be entered.how to get ip address of that in Windows Phone 8?

Please provide code snippet if possible

Thanks in advance.

解决方案

You can use class DeviceNetworkInformation. 

Try this code:

private void ResolveHostName(String hostName)
{
    var endPoint = new DnsEndPoint(hostName, 80);
    Microsoft.Phone.Net.NetworkInformation.DeviceNetworkInformation.ResolveHostNameAsync(endPoint, OnNameResolved, null);
}

private void OnNameResolved(Microsoft.Phone.Net.NetworkInformation.NameResolutionResult result)
{
    IPEndPoint[] endpoints = result.IPEndPoints;
    // Here your address if resolved
    if (endpoints != null && endpoints.Length > 0)
    {
        var ipAddress = endpoints[0].Address;
    }
}

and use it calling ResolveHostName("www.google.com");


这篇关于如何在Windows Phone 8中将主机名解析为IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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