【问题标题】:Find ip of certain windows phone device in your local network在本地网络中查找某些 windows phone 设备的 ip
【发布时间】:2014-11-10 04:41:22
【问题描述】:

我正在尝试构建 C# 应用程序(桌面,Windows,现在并不重要),我想用它连接到我的 Windows 手机,使用套接字来传输一些数据......我知道如何做到这一点。

通过套接字连接时,我不想手动输入 Windows Phone 设备的 IP 地址。所以我想知道是否可以从 Windows 手机应用程序发送一些带有一些消息的 HTTP 请求,并在计算机上获取该消息,以确定哪个 IP 是 Windows 手机的 IP?

也就是说,如何从网络上设备的Bunch of IP地址中知道哪个IP地址属于Windows phone的IP地址?

【问题讨论】:

    标签: c# sockets windows-phone-8 network-programming ip


    【解决方案1】:

    Here放开这个链接

    添加命名空间:

    使用 Windows.Networking;

     public static string FindIPAddress()
            {
                List<string> ipAddresses = new List<string>();
                var hostnames = NetworkInformation.GetHostNames();
                foreach (var hn in hostnames)
                {
                    //IanaInterfaceType == 71 => Wifi
                    //IanaInterfaceType == 6 => Ethernet (Emulator)
                    if (hn.IPInformation != null && 
                        (hn.IPInformation.NetworkAdapter.IanaInterfaceType == 71 
                        || hn.IPInformation.NetworkAdapter.IanaInterfaceType == 6))
                    {
                        string ipAddress = hn.DisplayName;
                        ipAddresses.Add(ipAddress);
                    }
                }
    
                if (ipAddresses.Count < 1)
                {
                    return null;
                }
                else if (ipAddresses.Count == 1)
                {
                    return ipAddresses[0];
                }
                else
                {
                    //if multiple suitable address were found use the last one
                    //(regularly the external interface of an emulated device)
                    return ipAddresses[ipAddresses.Count - 1];
                }
            }
    

    编辑:

    如果我错了,您想从一堆 IP 地址中获取特定的 Windows Phone IP 地址。 AFAIK你不能这样。但我建议你在获取 Windows Phone 的 IP 时附加一些字符串,如下所示,通过查看它会与其他 IP 地址有所不同。

        string IPadd = FindIPAddress();    
        string WPIPadd = IPadd + " - Windows phone "
        MessageDialog.show(WPIPadd);
    

    如果您发现除此之外的任何新内容,请告诉我们。谢谢

    【讨论】:

    • 这将告诉我 windows phone 设备的 ip,如果我在设备上运行代码.. 我想在计算机上运行代码并获取 windows phone 的 ip
    • I want to run code on computer and get ip of windows phone 我没有得到你的上下文。你能描述更多吗..?
    • 一个应用程序在计算机上,并查找网络中的所有设备.. 当它获得所有 IP 时,我想从所有 IP 中获取 Windows Phone 设备的 IP 并使用连接到 Windows phone 设备插座..
    • 如果我不知道哪个 IP 是 WP 的 IP,我不能在 WP 的 IP 上附加一些东西!!
    • 好的。现在我明白你的意思了。在那种情况下,我帮不了你。对不起
    猜你喜欢
    • 2018-02-20
    • 1970-01-01
    • 2014-05-25
    • 1970-01-01
    • 1970-01-01
    • 2015-12-06
    • 1970-01-01
    • 2018-05-16
    • 1970-01-01
    相关资源
    最近更新 更多