Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get SSID of the wireless network I am connected to with C# .Net on Windows Vista

I'd like to know if there is any .Net class that allows me to know the SSID of the wireless network I'm connected to. So far I only found the library linked below. Is the best I can get or should I use something else? Managed WiFi (http://www.codeplex.com/managedwifi)

The method that exploits WMI works for Windows XP but is it not working anymore with Windows Vista.

like image 251
mariosangiorgio Avatar asked Jan 10 '09 21:01

mariosangiorgio


People also ask

How do I find my SSID on Windows 10?

A computer automatically recognizes new wireless connections by reading the SSID name the network broadcasts. When users access the Wi-Fi settings in Windows 10 by clicking Start, Settings, Network & Internet, and then selecting the Wi-Fi entry, the SSID appears in the list of available wireless network connections.


2 Answers

I resolved using the library. It resulted to be quite easy to work with the classes provided:

First I had to create a WlanClient object

wlan = new WlanClient(); 

And then I can get the list of the SSIDs the PC is connected to with this code:

Collection<String> connectedSsids = new Collection<string>();  foreach (WlanClient.WlanInterface wlanInterface in wlan.Interfaces) {    Wlan.Dot11Ssid ssid = wlanInterface.CurrentConnection.wlanAssociationAttributes.dot11Ssid;    connectedSsids.Add(new String(Encoding.ASCII.GetChars(ssid.SSID,0, (int)ssid.SSIDLength))); } 
like image 197
mariosangiorgio Avatar answered Sep 22 '22 08:09

mariosangiorgio


We were using the managed wifi library, but it throws exceptions if the network is disconnected during a query.

Try:

var process = new Process {     StartInfo =     {     FileName = "netsh.exe",     Arguments = "wlan show interfaces",     UseShellExecute = false,     RedirectStandardOutput = true,     CreateNoWindow = true     } }; process.Start();  var output = process.StandardOutput.ReadToEnd(); var line = output.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(l => l.Contains("SSID") && !l.Contains("BSSID")); if (line == null) {     return string.Empty; } var ssid = line.Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries)[1].TrimStart(); return ssid; 
like image 25
Byron Ross Avatar answered Sep 19 '22 08:09

Byron Ross