If two WiFi networks exist with similar SSIDs, how can you distinguish between the two in code?

1.9k Views Asked by At

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.

3

There are 3 best solutions below

1
Mike Petrichenko On

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.

0
Jelle Jan On

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.

0
Jophy job On

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);