Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting current IP of windows phone 7

I am building a windows phone 7.1 app. I need to find out if the phone is connected to any Wifi and if so, what is its current IP in the local network (ie. 192.168.0.100 like this). I've been trying to find out these information for some time now. Please help.

I've managed to get the local IP on my console app by using the following code

public void ScanIP()
{                
    IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
    foreach (IPAddress ip in host.AddressList)
    {
        if (ip.AddressFamily == AddressFamily.InterNetwork)
        {
            String localIP = ip.ToString();
            Console.WriteLine(localIP);                        
        }
    }

    Console.ReadKey();
}

However, I need similar thing done for windows mobile 7 app. Any idea ? Please share.

like image 309
Arman Avatar asked Nov 03 '22 11:11

Arman


1 Answers

Do a multicast and listen for replies. Once you identify your multicast message, you can get the IP of the sender (which is yourself). You can use UdpAnySourceMulticastClient to do the multicasting. In case you're not in a wifi network, you will get a socket failure in the EndJoinGroup call. You should handle the exception and pass a specific value indicating you're not in a wifi network.

More info in this blog post by Andy Pennell.

like image 136
Unglückspilz Avatar answered Nov 16 '22 12:11

Unglückspilz