Finding the SSID of your wi-fi network on Windows Phone 7.5 Mango

Finding your IP address I have already covered, now for the next useful thing: your SSID name.

Although MSDN documentation seems a little sparse in this area, this function works well for me so far. Note that simply enumerating until you get a wireless network is insufficient, as recently-used networks also show up: the trick is to also check the connection state.

 public string GetSSIDName()
{
    foreach (var network in new NetworkInterfaceList())
    {
        if (
            (network.InterfaceType == NetworkInterfaceType.Wireless80211) &&
            (network.InterfaceState == ConnectState.Connected)
            )
        {
            return network.InterfaceName;
        }
    }
    return "<Not connected>";
}