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

查看:160
本文介绍了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天全站免登陆