Finding your current Wifi SSID
on 05.13.04, 08:41am in .net • comments (0)
The other day, I had a need to programmatically figure out what the name of the Wifi network I was connected to. Thought I’d share the code:
ManagementClass mc = new ManagementClass(”root\\WMI”, “MSNdis_80211_ServiceSetIdentifier”, null);
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
string wlanCard = (string)mo["InstanceName"];
bool active = (bool)mo["Active"];
byte[] ssid = (byte[])mo["Ndis80211SsId"];
string ssidString = Encoding.ASCII.GetString(ssid);
Console.WriteLine(”{0}\r\n{1}\r\n{2}”, wlanCard, active, ssidString);
Console.WriteLine();
}
WMI Rules.



