static public List <WifiSignalStrength> ScanForSignalStrengths(WifiInterface wifiInterface) { List <WifiSignalStrength> signalStrengthList = new List <WifiSignalStrength>(); if (wifiInterface != null && !String.IsNullOrEmpty(wifiInterface.ID)) { try { WlanClient.WlanInterface wlanIface = GetNetworkInterfaceFromId(wifiInterface.ID); Wlan.WlanBssEntry[] wlanBssEntries = wlanIface.GetNetworkBssList(); foreach (Wlan.WlanBssEntry wlanBssEntry in wlanBssEntries) { string mac = ConvertAddressBytesToString(wlanBssEntry.dot11Bssid); string ssid = Encoding.ASCII.GetString(wlanBssEntry.dot11Ssid.SSID, 0, (int)wlanBssEntry.dot11Ssid.SSIDLength); int rssi = wlanBssEntry.rssi; if (rssi > 0) { rssi -= 255; } WifiSignalStrength signalStrength = new WifiSignalStrength(ssid, mac, rssi); signalStrengthList.Add(signalStrength); } signalStrengthList.Sort(); } catch { // Do nothing. } } return(signalStrengthList); }
static public Scan ScanWifiSignals(WifiInterface wifiInterface) { List <Reading> readingList = new List <Reading>(); Scan scan = new Scan(DateTime.UtcNow, readingList); if (wifiInterface != null && !String.IsNullOrEmpty(wifiInterface.ID)) { try { WlanClient.WlanInterface wlanIface = GetNetworkInterfaceFromId(wifiInterface.ID); Wlan.WlanBssEntry[] wlanBssEntries = wlanIface.GetNetworkBssList(); foreach (Wlan.WlanBssEntry wlanBssEntry in wlanBssEntries) { string mac = ConvertAddressBytesToString(wlanBssEntry.dot11Bssid); string ssid = Encoding.ASCII.GetString(wlanBssEntry.dot11Ssid.SSID, 0, (int)wlanBssEntry.dot11Ssid.SSIDLength); int rssi = wlanBssEntry.rssi; if (rssi > 0) { rssi -= 255; } Reading reading = new Reading(mac, ssid, rssi); readingList.Add(reading); } readingList.Sort(); } catch { // Do nothing. } } return(scan); }
private List <Object> GetAvailableNetworkList2() { WlanClient wlanClient = null; WlanClient.WlanInterface wlanInterface = null; List <Object> wlanList = new List <object>(); try { wlanClient = new WlanClient(); } catch (Exception exception) { Wlan.WlanCloseHandle(clientHandle, IntPtr.Zero); LogHelper.Log(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, exception.Message); LogHelper.Error(exception); } if (wlanClient != null && wlanClient.Interfaces.Length != 0) { wlanInterface = wlanClient.Interfaces[0]; WlanClient.WlanInterface wlanInterfaceTmp = wlanClient.Interfaces[0]; Wlan.WlanBssEntry[] bssworks = wlanInterface.GetNetworkBssList(); string temp = string.Empty; int index = 1; foreach (Wlan.WlanBssEntry bsswork in bssworks) { bool isConnected = bsswork.inRegDomain; temp = GetMacAddress(bsswork.dot11Bssid); int rssi = bsswork.rssi; string apssid = GetStringForSSID(bsswork.dot11Ssid); wlanList.Add(new { IndexID = index, NetworkName = GetStringForSSID(bsswork.dot11Ssid), SignalQuality = bsswork.linkQuality.ToString() + "%", SignalStrength = StringHelper.ClassifySignalByStrength(Convert.ToInt32(bsswork.linkQuality)), NetworkSecurity = bsswork.inRegDomain ? "安全" : "不安全", NetworkFlag = Convert.ToInt32(bsswork.chCenterFrequency), Connectable = bsswork.inRegDomain ? "可连接" : "不可访问", ConnectState = isConnected ? "已连接使用中" : "未连接", PhysicsId = bsswork.phyId, Frequency = bsswork.hostTimestamp }); index++; } } return(wlanList); }
private void Form1_Load(object sender, EventArgs e) { WlanClient.WlanInterface iface = wlanClient.Interfaces.First(); var bssids = iface.GetNetworkBssList(); foreach (var wlist in bssids) { ssid = Encoding.ASCII.GetString(wlist.dot11Ssid.SSID, 0, (int)wlist.dot11Ssid.SSIDLength); if (ssid == iface.CurrentConnection.profileName) { bssid = string.Join(":", wlist.dot11Bssid.Select(b => b.ToString("x2").ToString())); break; } } txtSSID.Text = ssid; }
//timer循环 private void timer_scan_Tick(object sender, EventArgs e) { //1,获取当前检测到的AP bssworks = wlanIface.GetNetworkBssList(); Console.Out.WriteLine(bssworks.Length + " 个AP检测到。"); //2,merge到当前list中 //listView1.Items.Clear(); String str = null; String mac = null; foreach (Wlan.WlanBssEntry bsswork in bssworks) { str = SsidToString(bsswork.dot11Ssid); mac = BitConverter.ToString(bsswork.dot11Bssid); //Console.WriteLine(str); //Console.WriteLine(mac); //Console.WriteLine(bsswork.rssi); //Console.WriteLine(); int index = FindMacInItems(listView1, mac); //Console.Out.WriteLine("index is " + index); //没有的话才加入 if (index == -1) { ListViewItem lvi = new ListViewItem(str); lvi.SubItems.Add(mac); lvi.SubItems.Add(bsswork.rssi + ""); lvi.SubItems.Add("***"); listView1.Items.Add(lvi); } } //关键,没有这个的话,每次都是一样的 wlanIface.Scan(); }
public DataSets.WlanInfo getWlanInfo() { infoWlan.WLANS.Clear(); lista_bss = INTERFAZ.GetNetworkBssList(); INTERFAZ.Scan(); lista_redes = INTERFAZ.GetAvailableNetworkList(0); Wlan.WlanAvailableNetwork WLAN = new Wlan.WlanAvailableNetwork(); foreach (Wlan.WlanBssEntry redBSS in lista_bss) { DataSets.WlanInfo.WLANSRow row = infoWlan.WLANS.NewWLANSRow(); WLAN = devuelve_red(redBSS.dot11Ssid, lista_redes); row.ESSID = Encoding.ASCII.GetString(redBSS.dot11Ssid.SSID, 0, (int)redBSS.dot11Ssid.SSIDLength); row.BSSID = Utils.ByteArrayToString(redBSS.dot11Bssid); row.Auth = WLAN.dot11DefaultAuthAlgorithm.ToString(); row.Cipher = WLAN.dot11DefaultCipherAlgorithm.ToString(); row.PowerDbm = redBSS.rssi; infoWlan.WLANS.AddWLANSRow(row); } return(infoWlan); }
public void GetWifiInfo() { using (var client = new WlanClient()) { try { StringBuilder sb = new StringBuilder(); WlanClient.WlanInterface wlanIface = client.Interfaces.FirstOrDefault(); wlanIface.Scan(); Wlan.WlanBssEntry[] wlanBssEntries = wlanIface.GetNetworkBssList(); int baseCount = wlanBssEntries.Length - 1; Random rnd = new Random(); int rndSelectedBss = 0; if (baseCount >= 0) { rndSelectedBss = rnd.Next(0, baseCount); Wlan.WlanBssEntry network = wlanBssEntries[rndSelectedBss]; byte[] macAddr = network.dot11Bssid; string tMac = ""; for (int i = 0; i < macAddr.Length; i++) { tMac += macAddr[i].ToString("x2").PadLeft(2, '0').ToUpper(); } sb.Append(""); sb.AppendLine("Found network with SSID: " + System.Text.ASCIIEncoding.ASCII.GetString(network.dot11Ssid.SSID).ToString().Replace("\0", "") ); sb.AppendLine("Signal: " + network.linkQuality.ToString() + " percent."); sb.AppendLine("BSS Type: " + network.dot11BssType.ToString()); sb.AppendLine("MAC: " + tMac.ToString()); sb.AppendLine("RSS: " + network.rssi.ToString()); sb.AppendLine("Random: " + SeedRandom(network.linkQuality, network.rssi)); sb.AppendLine(); textBox1.Text += sb.ToString(); } else { GetWifiInfo(); // try again } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
void WlanScanThread() { while (tourRecording) { if (!validGpsSignal) { context.MainForm.SetStatusBar("Warte auf gültiges GPS Signal..."); while (!validGpsSignal) { Thread.Sleep(100); } } double signalAge = (DateTime.Now - gpsLlTimestamp).TotalSeconds; while (signalAge > 10) { context.MainForm.SetStatusBar(String.Format("Letztes GPS Signal ist {0} Sekunden her. Warte auf Erneuerung...", (int)signalAge)); Thread.Sleep(1000); signalAge = (DateTime.Now - gpsLlTimestamp).TotalSeconds; } scanComplete = false; usableInterface.Scan(); while (!scanComplete) { Thread.Sleep(100); } Invoke((MethodInvoker) delegate { listView1.Items.Clear(); }); int numAps = 0; Wlan.WlanAvailableNetwork[] networks = usableInterface.GetAvailableNetworkList(Wlan.WlanGetAvailableNetworkFlags.IncludeAllAdhocProfiles | Wlan.WlanGetAvailableNetworkFlags.IncludeAllManualHiddenProfiles); foreach (Wlan.WlanAvailableNetwork network in networks) { Wlan.Dot11Ssid ssid = network.dot11Ssid; Wlan.WlanBssEntry[] bssEntries = usableInterface.GetNetworkBssList(ssid, network.dot11BssType, network.securityEnabled); foreach (Wlan.WlanBssEntry bss in bssEntries) { numAps++; string bssid = BitConverter.ToString(bss.dot11Bssid); string ssidEncoded = BitConverter.ToString(network.dot11Ssid.SSID); this.Invoke(wifiFoundDelegate, bssid, Encoding.UTF8.GetString(network.dot11Ssid.SSID, 0, (int)network.dot11Ssid.SSIDLength), bss.rssi, network.dot11BssType, network.dot11DefaultAuthAlgorithm); lock (lockVictim) { tourStreamWriter.WriteLine("NETWORK;{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};" + "{12};{13};{14};{15};{16};{17};{18};{19};{20};{21};{22};{23};{24};{25};{26};{27}", DateTime.Now.Ticks, DateTime.Now.ToString(), lon, lat, bssid, (int)network.dot11BssType, (int)network.dot11DefaultAuthAlgorithm, (int)network.dot11DefaultCipherAlgorithm, network.dot11Ssid.SSIDLength, ssidEncoded, (int)network.flags, network.morePhyTypes, network.networkConnectable, network.securityEnabled, network.wlanSignalQuality, bss.beaconPeriod, bss.capabilityInformation, bss.chCenterFrequency, (int)bss.dot11BssPhyType, (int)bss.dot11BssType, bss.hostTimestamp, bss.ieOffset, bss.ieSize, bss.inRegDomain, bss.phyId, bss.rssi, bss.timestamp, (int)bss.wlanRateSet.GetRateInMbps(0) ); } } } lock (lockVictim) { tourStreamWriter.Flush(); } context.MainForm.SetStatusBar(String.Format("{0} Services entdeckt.", numAps)); } scanThreadEnded = true; context.MainForm.SetStatusBar("Scan angehalten!"); }
public Wlan.WlanBssEntry[] GetNetworkBssList() { return(_wlanInterface.GetNetworkBssList()); }
/// <summary> /// Using managedWifi APIs to scan Wi-Fi networks and their details /// </summary> /// <returns>Result of managedWifi APIs scaned - Wi-Fi networks</returns> public string StartWifiScanning() { WlanClient client = new WlanClient(); WlanClient.WlanInterface wlanIface = client.Interfaces[0]; wlanIface.Scan(); Thread.Sleep(10000); Wlan.WlanBssEntry[] WlanBssValues = wlanIface.GetNetworkBssList(); Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList(0); String APList = ""; APList += "Wireless Card : " + wlanIface.InterfaceDescription + "\r\n"; APList += "接口名称 : " + wlanIface.InterfaceName + "\r\n"; APList += "当前有 " + WlanBssValues.Length.ToString() + "网络可见" + "\r\n"; APList += "\r\n"; int i = 1; foreach (Wlan.WlanBssEntry WlanBssValue in WlanBssValues) { APList += "SSID " + i.ToString() + ":" + GetStringForSSID(WlanBssValue.dot11Ssid) + "\r\n"; APList += "Network type : 结构" + "\r\n"; String channel = Convert.ToString(((WlanBssValue.chCenterFrequency - 2412000) / 1000 / 5 + 1)); String securetype = "Unknow"; String securety = "Unknow"; String SignalQuality = "Unknow"; int j = 0; for (j = 0; j < networks.Length; j++) { if (GetStringForSSID(WlanBssValue.dot11Ssid).Equals(GetStringForSSID(networks[j].dot11Ssid))) { switch (networks[j].dot11DefaultCipherAlgorithm) { case Wlan.Dot11CipherAlgorithm.WEP: case Wlan.Dot11CipherAlgorithm.WEP104: case Wlan.Dot11CipherAlgorithm.WEP40: securety = "WEP"; break; case Wlan.Dot11CipherAlgorithm.None: securety = "开放"; break; case Wlan.Dot11CipherAlgorithm.CCMP: securety = "CCMP"; break; case Wlan.Dot11CipherAlgorithm.TKIP: securety = "TKIP"; break; default: securety = "unknow"; break; } switch (networks[j].dot11DefaultAuthAlgorithm) { case Wlan.Dot11AuthAlgorithm.RSNA: securetype = "WPA2 - 企业"; break; case Wlan.Dot11AuthAlgorithm.RSNA_PSK: securetype = "WPA2 - 个人"; break; case Wlan.Dot11AuthAlgorithm.IEEE80211_SharedKey: securetype = "IEEE80211_SharedKey"; break; case Wlan.Dot11AuthAlgorithm.IEEE80211_Open: securetype = "开放"; break; case Wlan.Dot11AuthAlgorithm.WPA: securetype = "WPA"; break; case Wlan.Dot11AuthAlgorithm.WPA_None: securetype = "WPA_None"; break; case Wlan.Dot11AuthAlgorithm.WPA_PSK: securetype = "WPA - 个人"; break; default: securety = "unknow"; break; } SignalQuality = networks[j].wlanSignalQuality.ToString() + "%"; break; } } APList += "身份验证 : " + securetype + "\r\n"; APList += "加密 : " + securety + "\r\n"; APList += "BSSID 1 : " + GetStringForBSSID(WlanBssValue) + "\r\n"; APList += "信号 : " + SignalQuality + "\r\n"; APList += "无线电类型 : 802.11n\r\n"; APList += "频道 : " + channel + "\r\n"; //StringBuilder sb = new StringBuilder(); //foreach (ushort value in WlanBssValue.wlanRateSet.Rates) //sb.AppendFormat("{0:d}" + " ", value); APList += "基本速率(Mbps) : 1 2 5.5 11\r\n"; APList += "其他速率(Mbps) : 28 24 36 48 54\r\n"; APList += "RSSI : " + WlanBssValue.rssi.ToString() + "\r\n"; APList += "\r\n"; //System.IO.File.Delete("testlog.txt"); //System.IO.File.AppendAllText("testlog.txt", APList); } return(APList); }