470,596 Members | 1,408 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,596 developers. It's quick & easy.

WMI Wifi discovery

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_ServiceSetIdentifi er 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

Jun 5 '07 #1
1 15510
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_ina lámbricas);
ManagementObjectSearcher managementObjectSearcher = new
ManagementObjectSearcher(managementScope, objectQuery);
ManagementObjectCollection moc = managementObjectSearcher.Get();
ManagementObjectCollection.ManagementObjectEnumera tor 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[i] != '\0'; i++)
{
Console.Write(ssid[i]);
}
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");
}
}
}
}
}
"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.

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

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

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

Console.WriteLine("MSNdis_80211_ServiceSetIdentifi er 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

Jul 12 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Anurag | last post: by
3 posts views Thread by Jon Vaughan | last post: by
4 posts views Thread by Tarun | last post: by
7 posts views Thread by Chris Mullins | last post: by
Elias Alhanatis
4 posts views Thread by Elias Alhanatis | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.