Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
478 views
in Technique[技术] by (71.8m points)

IP address in 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...