11

I'm writing a small network management tool. In order to pull out the details for various WiFi networks, I'm making calls to the wlanapi.dll, WlanGetProfile(...) API method to get the profile information for each available WiFi network.

Assuming two local WiFi networks have similar SSIDs, how can I query information on these two networks and distinguish between the two when I present the information to the user?

I am writing my app in C#, however, generalized details that are not code-specific can be provided if they will give me the answers that I needed. However, I'm tagging this as C#/.Net because if there is a way to get this information using native .Net libraries, I'd appreciate C# code samples.

RLH
  • 15,230
  • 22
  • 98
  • 182
  • Are you looking for the equivalent of the command `netsh wlan show networks mode=bssid`? here in C#/powershell: https://jordanmills.wordpress.com/2013/09/26/how-to-list-ssids-in-powershell-without-parsing-command-line-output/ ? – Simon Mourier Apr 06 '18 at 21:32
  • WlanGetAvailableNetworkList https://msdn.microsoft.com/en-us/library/windows/desktop/ms706749(v=vs.85).aspx provides available networks. Uniquely identifiable by bssid (mac addr) – Mardoxx Apr 08 '18 at 17:21
  • In addition to the mac address, I think it's possibly more useful to identify the frequency, channel, and channel width of the ssid. It becomes more clear as a user when we get to see where they exist in the wifi space. (is one 2.4Ghz and the other 5Ghz?) – caesay Apr 10 '18 at 20:30
  • @RLH none of the answers was useful to you to open a bounty? that code should work on Xamarin –  Apr 13 '18 at 10:30
  • @LiquidCore I've given you the answer mark/bounty. I hold off on my bounties until the end. This is strategic and to get attention. No offense. Thanks for your excellent answer. – RLH Apr 13 '18 at 14:01
  • @RLH You're welcome, fellow programmer :) I was just curious if the provided answer was valid or not, not rep/bounty greedy or something. I always like to improve and know if my knowledge works or is obsolete –  Apr 16 '18 at 09:12

3 Answers3

4

There is no prolem with detecting few networks with the same SSID because they have different MACs.

However it looks there is no way to connect to selected one because no way to specify a MAC when connectiong.

  • 1
    Yes it does you can provide pDesiredBssidList https://msdn.microsoft.com/en-us/library/windows/desktop/ms706851(v=vs.85).aspx to WlanConnect – Mardoxx Apr 08 '18 at 17:18
1

This Code project sample so the same Link : A-Vista-Wireless-Network-Scanner

enter image description here

Process proc = new Process();
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.FileName = "netsh";
proc.StartInfo.Arguments = "wlan show networks mode=bssid";
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.Start();
output = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();

Connect with mac:

//// Connects to a known network with WEP security
string profileName = "Cheesecake"; // this is also the SSID
string mac = "52544131303235572D454137443638";
string key = "hello";
string profileXml = string.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><hex>{1}</hex><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><MSM><security><authEncryption><authentication>open</authentication><encryption>WEP</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>networkKey</keyType><protected>false</protected><keyMaterial>{2}</keyMaterial></sharedKey><keyIndex>0</keyIndex></security></MSM></WLANProfile>", profileName, mac, key);

wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, true);
wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName);
Jophy job
  • 1,924
  • 2
  • 20
  • 38
0

Different networks with the same SSID will still have different MAC-addresses.

This also goes for different access-points for the same network.

Unfortunately i have no idea how to query the MAC-address for you to check.

Jelle Bleeker
  • 131
  • 11