IP address in windows phone 8

前端 未结 3 1684
你的背包
你的背包 2020-12-02 01:33

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 (unbelievabl

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 02:30

    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 ipAddresses = new List();
    
        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

提交回复
热议问题