Windowscommunitytoolkit: Know network ssid connected to

Created on 24 Dec 2016  ·  22Comments  ·  Source: windows-toolkit/WindowsCommunityToolkit

From ConnectionHelper class we can only get Get precise connection type but can you please extend this functionality and we can know the network SSID user is connected to?
Btw excellent work by you guys it helps developing uwp apps a lot easier!

helpers improvements

Most helpful comment

screenshot 31

I have added another method to Connection Helper that seems to work. If there is interest, I could push this as PR

All 22 comments

I suppose we can get this property easily through the property WlanConnectionProfileDetails of the InternetConnectionProfile class https://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.connectionprofile

what if the user is connected to a wifi but not have internet access then how would we get the ssid?

I understand what you said but I have no idea if it's possible.

Hi, I have created this function that will return the ssid of the current network connected even when the wifi have no internet access:

    `/// <summary>
    /// Gets connection ssid for the current Wifi Connection.
    /// </summary>
    /// <returns> string value of current ssid/></returns>
    /// 
    public static async Task<string> NetwoksSSid()
    {  
            try
            {
               WiFiAdapter firstAdapter;
               var access = await  WiFiAdapter.RequestAccessAsync();
               if (access != WiFiAccessStatus.Allowed)
                 {
                    return "Acess Denied for wifi Control";
                 }
               else
                {
                    var result = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(WiFiAdapter.GetDeviceSelector());
                    if (result.Count >= 1)
                    {
                        firstAdapter = await WiFiAdapter.FromIdAsync(result[0].Id);
                    }
                    else
                    {
                        return "No WiFi Adapters detected on this machine";
                    }
                var connectedProfile = await firstAdapter.NetworkAdapter.GetConnectedProfileAsync();
                if (connectedProfile != null)
                    {
                    return connectedProfile.ProfileName;
                 }
               else if (connectedProfile == null)
                {

                    return "WiFi adapter disconnected";
               }
            }
            }
            catch
            {

            }          

            return null;

        }`

and I have checked and its working .I can put this method into ConnectionHelper.cs and make a pr if you think it would be good @Odonno

@bitloks Thanks for your help. Your code seems really interesting.

I recommend you to create a PR but I have some suggestions to offer you considering what I see :

  • Rename method to GetNetworkSsid
  • Instead of returning pure string (like "WiFi adapter disconnected"), it would be better if you throw an Exception with a message so that when someone want to use the network ssid he only has to check for null and catch an exception eventually

@ripdollar ConnectionProfile class has a method called GetNetworkNames shouldn't that return SSID assuming that its a WiFi connection ? for other connection types it would return the network name as such..

screenshot 31

I have added another method to Connection Helper that seems to work. If there is interest, I could push this as PR

@deltakosh any thoughts ?

@hermitdave sure push that PR as it is surely helpful and also can you please tell me why am I getting this error
screenshot 8

whenever I am adding my method to ConnectionHelper.cs just for knowledge :)

Try adding using System; to the namespace declaration list

@hermitdave thanks it worked! 👍 don't know why IntelliSense wasn't showing any potential fix.
screenshot 9

Also @hermitdave if you allow I can also put this method in ConnectionHelper.Cs and push a PR in which even though internet is not there it would give the network SSID on a wifi connection.Though I am skeptical of my method performance.I think your method must have taken a different approach with a better performance :).

@bitloks my method is simpler :)

public static IReadOnlyList<string> NetworkNames
{
    get
    {
        ConnectionProfile profile = null;

        try
        {
            profile = NetworkInformation.GetInternetConnectionProfile();
        }
        catch
        {
        }

        if (profile != null)
        {
            return profile.GetNetworkNames();
        }

        return null;
    }
}

Having said that above only works for ConnectionProfile with Internet connection. However NetworkInformation provides FindConnectionProfiles this method takes ConnectionProfileFilter. ConnectionProfileFilter in turn has a property called IsWlanConnectionProfile this would allow identifying WiFi connections and you can use GetNetworkNames method to retrieve SSID associated with that WiFi connection

Did not see the PR associated with it? Did I miss it?

Still no PR as I remember.

@bitloks still motivated to push a PR?

@deltakosh question is do we GetNetworkNames with filter?. If filter is null, we use current internet profile. @bitloks can implement it

yes :)

Hey guys sorry was kind of busy as my new semester started will push the pr
soon sorry again :)

On 4 Jan 2017 01:40, "David Catuhe" notifications@github.com wrote:

yes :)


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/UWPCommunityToolkit/issues/743#issuecomment-270211498,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJNgU-v0hzijqSWgmpgZBEYWR53DFRG-ks5rOqsngaJpZM4LVNbR
.

No worries..

I think we are looking to launch next version in early Feb. If you want to push a PR now would be a good time to start

Sorry for not pushing but this weekend i will surely do it :)

On Thu, Jan 19, 2017 at 2:49 AM, Hermit Dave notifications@github.com
wrote:

I think we are looking to launch next version in early Feb. If you want to
push a PR now would be a good time to start


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/UWPCommunityToolkit/issues/743#issuecomment-273604838,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJNgU2PoAyrRgkqch1mWfz9nCke0GmvHks5rToHSgaJpZM4LVNbR
.

Was this page helpful?
0 / 5 - 0 ratings