private static SSID MakeSSID(string output, string interfaceState) { SSID ssid; string name = gv(output, "SSID"); string bssid = gv(output, "BSSID"); string signal = gv(output, "Signal"); decimal rx_rate = Convert.ToDecimal(gv(output, "Receive")); decimal tx_rate = Convert.ToDecimal(gv(output, "Transmit")); int channel = Convert.ToInt32(gv(output, "Channel")); string radio = gv(output, "Radio").Remove(0, 6); string cipher = gv(output, "Cipher"); string security = gv(output, "Authentication").Replace("-", "_"); ssid = new SSID(name, bssid, signal, rx_rate, tx_rate, channel, (Radio)Enum.Parse(typeof(Radio), radio), (Cipher)Enum.Parse(typeof(Cipher), cipher), (Security)Enum.Parse(typeof(Security), security), (InterfaceState)Enum.Parse(typeof(InterfaceState), interfaceState)); return(ssid); }
private static void ConnectedMessage(SSID ssid) { string message = "Wi-Fi connected to " + ssid.Name + " " + ssid.BSSID + " " + ssid.Signal; Console.WriteLine(message); ShowToast(message); }
private static void scrape_netsh() { Process p = new Process(); p.StartInfo.FileName = "netsh.exe"; p.StartInfo.Arguments = "wlan show interfaces"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; SSID ssid = null; bool connected = false; for (;;) // enter cryptic loop { p.Start(); string output = p.StandardOutput.ReadToEnd(); string interfaceState = gv(output, "State"); if (interfaceState == "connected") { if (ssid == null) { ssid = MakeSSID(output, interfaceState); ConnectedMessage(ssid); p.WaitForExit(); connected = true; continue; // goto start of cryptic loop } string checkSSID = gv(output, "SSID"); if (checkSSID != ssid.Name) { ssid = MakeSSID(output, interfaceState); } string checkBSSID = gv(output, "BSSID"); if (!connected) // if i wasn't connected before, it's a new connection. { connected = true; ConnectedMessage(ssid); } if (ssid.BSSID != checkBSSID) // if interface was connected, check to see if there is a new BSSID indicating a BSS ROAM. { ssid.BSSID = checkBSSID; RoamMessage(ssid.Name, ssid.BSSID, checkBSSID); } } if (interfaceState == "disconnected" && connected) { Console.WriteLine("Wi-Fi is disconnected"); connected = false; continue; } p.WaitForExit(); Thread.Sleep(100); } }