Windows Phone 8 中的 IP 地址 [英] IP address in windows phone 8

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

问题描述

我需要找到运行我的软件的电话的 IP 地址.我原以为这是直截了当的,但在搜索论坛后,似乎(令人难以置信)在 Windows Phone 7 中没有这种方法 - 但是,这在 Windows Phone 8 中是否发生了变化?任何帮助将不胜感激.

i need to find the IP address of the phone my software is running on. I would have thought that is straight forward but having searched the forums it seems like (unbelievably enough) that there isn't a method for this in windows phone 7 - however, has this changed in windows phone 8? any help would be appreciated.

推荐答案

是的,现在可以在 WP8 中实现,而无需使用 WP7 所需的多播解决方案.请注意,您的手机上将有多个网络接口(例如我的 WP8 模拟器上的三个)

Yes this is now possible in WP8 without using the multicast solution required for WP7. Note that you will have multiple network interfaces on your phone (e.g. three on my WP8 Emulator)

public static IPAddress Find()
{
    List<string> ipAddresses = new List<string>();

    var hostnames = NetworkInformation.GetHostNames();
    foreach (var hn in hostnames)
    {
        if (hn.IPInformation != null)
        {
            string ipAddress = hn.DisplayName;
            ipAddresses.Add(ipAddress);
        }
    }

    IPAddress address = IPAddress.Parse(ipAddresses[0]);
    return address;
}

HTH

这篇关于Windows Phone 8 中的 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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