WMI Wifi discovery

S

Srini

How do I discover the networks detected by my Wi-Fi adapter?
I tried to use WMI. It shows information of the connected network
only.
There are some other WiFi access points available. But I am not able
to retrieve them using WMI(using c# code). The code which I tried is
given below.

Please let me know if we can detect other access points, which is
available and not currently connected with my adapter.

ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\WMI",
"SELECT * FROM
MSNdis_80211_ServiceSetIdentifier");

foreach (ManagementObject queryObj in searcher.Get())
{

Console.WriteLine("-----------------------------------");

Console.WriteLine("MSNdis_80211_ServiceSetIdentifier instance");

Console.WriteLine("-----------------------------------");

if(queryObj["Ndis80211SsId"] == null)
Console.WriteLine("Ndis80211SsId: {0}",
queryObj["Ndis80211SsId"]);
else
{
Byte[] arrNdis80211SsId = (Byte[])
(queryObj["Ndis80211SsId"]);
foreach (Byte arrValue in arrNdis80211SsId)
{
Console.WriteLine("Ndis80211SsId: {0}",
arrValue);
}
}
}



Thanks
Srinivasan
 
G

Guest

using System;
using System.Collections.Generic;
using System.Management;
using System.Text;

namespace The_Wifi_Project
{


class Program
{
const string wql_listar_adaptadores_conectados = "SELECT * FROM
MSNdis_80211_BaseServiceSetIdentifier WHERE Active = True";
const string wql_listar_redes_inalámbricas = "SELECT * FROM
MSNDis_80211_BSSIList";


private static void WIFI_list()
{
/* Establecer una conexión con el entorno de administración */
ManagementScope managementScope = new
ManagementScope("\\\\.\\root\\wmi");

System.Management.ObjectQuery objectQuery = new
System.Management.ObjectQuery(wql_listar_redes_inalámbricas);
ManagementObjectSearcher managementObjectSearcher = new
ManagementObjectSearcher(managementScope, objectQuery);
ManagementObjectCollection moc = managementObjectSearcher.Get();
ManagementObjectCollection.ManagementObjectEnumerator moe =
moc.GetEnumerator();
moe.MoveNext();
ManagementBaseObject[] objarr =
(ManagementBaseObject[])moe.Current.Properties["Ndis80211BSSIList"].Value;

if (objarr != null)
{
foreach (ManagementBaseObject obj in objarr)
{
char[] ssid =
Encoding.ASCII.GetChars((byte[])obj["Ndis80211Ssid"]);
Console.Write("SSID: ");
int i;
for (i = 0; i < 32 && ssid != '\0'; i++)
{
Console.Write(ssid);
}
uint rs = (uint)obj["Ndis80211Rssi"];
Console.Write(".");
Console.WriteLine(" RSSI: " + rs);
}
}
}

static void Main(string[] args)
{
Console.Clear();

foreach (string argumento in args)
{
String argument = argumento.ToLower();
if (argument.Equals("list"))
{
WIFI_list();
break;
}
else
{
Console.WriteLine("Error: acción no reconocida");
}
}
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top