using System;
using System.Collecti ons.Generic;
using System.Manageme nt;
using System.Text;
namespace The_Wifi_Projec t
{
class Program
{
const string wql_listar_adap tadores_conecta dos = "SELECT * FROM
MSNdis_80211_Ba seServiceSetIde ntifier WHERE Active = True";
const string wql_listar_rede s_inalámbricas = "SELECT * FROM
MSNDis_80211_BS SIList";
private static void WIFI_list()
{
/* Establecer una conexión con el entorno de administración */
ManagementScope managementScope = new
ManagementScope ("\\\\.\\root\\ wmi");
System.Manageme nt.ObjectQuery objectQuery = new
System.Manageme nt.ObjectQuery( wql_listar_rede s_inalámbricas );
ManagementObjec tSearcher managementObjec tSearcher = new
ManagementObjec tSearcher(manag ementScope, objectQuery);
ManagementObjec tCollection moc = managementObjec tSearcher.Get() ;
ManagementObjec tCollection.Man agementObjectEn umerator moe =
moc.GetEnumerat or();
moe.MoveNext();
ManagementBaseO bject[] objarr =
(ManagementBase Object[])moe.Current.Pr operties["Ndis80211BSSIL ist"].Value;
if (objarr != null)
{
foreach (ManagementBase Object obj in objarr)
{
char[] ssid =
Encoding.ASCII. GetChars((byte[])obj["Ndis80211S sid"]);
Console.Write(" SSID: ");
int i;
for (i = 0; i < 32 && ssid[i] != '\0'; i++)
{
Console.Write(s sid[i]);
}
uint rs = (uint)obj["Ndis80211R ssi"];
Console.Write(" .");
Console.WriteLi ne(" RSSI: " + rs);
}
}
}
static void Main(string[] args)
{
Console.Clear() ;
foreach (string argumento in args)
{
String argument = argumento.ToLow er();
if (argument.Equal s("list"))
{
WIFI_list();
break;
}
else
{
Console.WriteLi ne("Error: acción no reconocida");
}
}
}
}
}
"Srini" wrote:
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.
ManagementObjec tSearcher searcher =
new ManagementObjec tSearcher("root \\WMI",
"SELECT * FROM
MSNdis_80211_Se rviceSetIdentif ier");
foreach (ManagementObje ct queryObj in searcher.Get())
{
Console.WriteLi ne("-----------------------------------");
Console.WriteLi ne("MSNdis_8021 1_ServiceSetIde ntifier instance");
Console.WriteLi ne("-----------------------------------");
if(queryObj["Ndis80211S sId"] == null)
Console.WriteLi ne("Ndis80211Ss Id: {0}",
queryObj["Ndis80211S sId"]);
else
{
Byte[] arrNdis80211SsI d = (Byte[])
(queryObj["Ndis80211S sId"]);
foreach (Byte arrValue in arrNdis80211SsI d)
{
Console.WriteLi ne("Ndis80211Ss Id: {0}",
arrValue);
}
}
}
Thanks
Srinivasan