public static Wlan.WlanConnectionAttributes GetWlanConnectInfo() { WlanClient wlanClientTmp = new WlanClient(); WlanClient.WlanInterface wlanInterfaceTmp = wlanClientTmp.Interfaces[0]; if (wlanInterfaceTmp.IsWlanConnection()) { Wlan.WlanConnectionAttributes wlanAttr = wlanInterfaceTmp.CurrentConnection; if (wlanAttr.isState == Wlan.WlanInterfaceState.Connected) { //string macAddress = GetMacAddress(wlanAttr.wlanAssociationAttributes.dot11Bssid); //tbState.Text = String.Format("当前设备已连接到Wlan: {0}, Mac地址: {1} IPv4地址: {2}", wlanAttr.profileName, macAddress, PathUtil.GetIPv4()); return(wlanAttr); } } return(new Wlan.WlanConnectionAttributes()); }
private void frmConnectWifiAdaptor_Load(object sender, EventArgs e) { //ShowNetworkInterfaces(); WlanClient client = new WlanClient(); WlanClient.WlanInterface[] interfaces = client.Interfaces; if (interfaces.Length == 1) { lblWifiAdaptor.Text = interfaces[0].InterfaceDescription; SelectedInterface = interfaces[0]; } interfaces[0].WlanConnectionNotification += new WlanClient.WlanInterface.WlanConnectionNotificationEventHandler(frmConnectWifiAdaptor_WlanConnectionNotification); interfaces[0].WlanNotification += new WlanClient.WlanInterface.WlanNotificationEventHandler(frmConnectWifiAdaptor_WlanNotification); interfaces[0].Scan(); Wlan.WlanAvailableNetwork[] networks = SelectedInterface.GetAvailableNetworkList(Wlan.WlanGetAvailableNetworkFlags.IncludeAllManualHiddenProfiles); ListNetworks = new List<Wlan.WlanAvailableNetwork>(); foreach (Wlan.WlanAvailableNetwork network in networks) { //string SSIDname = GetStringForSSID(network.dot11Ssid); if (GetStringForSSID(network.dot11Ssid) != "") { //network.profileName = GetStringForSSID(network.dot11Ssid); ListNetworks.Add(network); //listBox1.Items.Add(network); //string name = network.ProfileName; } } listBox1.DataSource = ListNetworks; listBox1.DisplayMember = "ProfileName"; listBox1.SelectedItem = ListNetworks[0]; if (CheckForInternetConnection()) tbStatus.Text = "Connected!"; else tbStatus.Text = "Waiting..."; }
private bool DetermineNextNetworkInterface() { currentlyScannedNetworkInterfaceNumber++; if (currentlyScannedNetworkInterfaceNumber >= client.Interfaces.Length) { ProcessConnectionFailed(); return false; } currentWifiInterface = client.Interfaces[currentlyScannedNetworkInterfaceNumber]; return true; }
private void ResetProgressVariables() { currentState = DroneNetworkConnectionState.NotConnected; currentPingRetries = 0; currentScanRetries = 0; currentlyScannedNetworkInterfaceNumber = -1; currentWifiInterface = null; }
public void SetWirelessConnection() { WlanClient.WlanInterface iface = null; String configIface = ""; bool bConfigIface = dConfig.TryGetValue("wirelessInterface",out configIface); lock (wClient) { foreach (WlanClient.WlanInterface wIface in wClient.Interfaces) { if (iface == null) { iface = wIface; } else if (bConfigIface) { if (wIface.InterfaceName == configIface) iface = wIface; } else { if (wIface.InterfaceName == "Wireless Network Connection") iface = wIface; } } } wlanIface = iface; if (wlanIface != null) lock (wlanIface) { wlanIface.WlanNotification += WlanEventHandler; } SetState(); }
public bool SetWlanInterface(WlanClient.WlanInterface wlanIface) { this.wifiInterface = wlanIface; return true; }
private void setCurrentWlanInterface(bool setMonitoring) { /* // Remove the callbacks, if any if (isMonitoringWifi && currentWlanInterface != null) { currentWlanInterface.WlanNotification -= wlanIface_WlanNotification; currentWlanInterface.WlanConnectionNotification -= wlanIface_WlanConnectionNotification; } */ currentWlanInterface = null; previousIsWifiConnected = isWifiConnected; isWifiConnected = false; // find the first connected interface foreach (WlanClient.WlanInterface wlanIface in wlanClient.Interfaces) { if (wlanIface.InterfaceState == Wlan.WlanInterfaceState.Connected) { isWifiConnected = true; currentWlanInterface = wlanIface; break; } } /* if (isWifiConnected && setMonitoring) { // set the callbacks ignoreOneConnectionNotification = true; currentWlanInterface.WlanNotification += wlanIface_WlanNotification; currentWlanInterface.WlanConnectionNotification += wlanIface_WlanConnectionNotification; } else if (setMonitoring) { // no interface connected, but we want to monitor. // let's register a callback on each interface to see when one gets connected foreach (WlanClient.WlanInterface wlanIface in wlanClient.Interfaces) { wlanIface.WlanConnectionNotification += wlanIface_WlanConnectionNotification; } } */ isMonitoringWifi = setMonitoring; }
public void start() { if (m_started) return; m_started = true; m_wlan = new WlanClient(); foreach (WlanClient.WlanInterface wlanInterface in m_wlan.Interfaces) { if (wlanInterface.NetworkInterface != null && wlanInterface.NetworkInterface.NetworkInterfaceType == System.Net.NetworkInformation.NetworkInterfaceType.Wireless80211) { m_wlanInterface = wlanInterface; } } if (m_wlanInterface == null) return; Thread threadHand1 = new Thread(() => { while (m_started) { if (stop_scan) continue; string str = Utils.GetSoftAPContractName(); str = str.Substring(str.IndexOf('_')); string tempwifi = GetWifiSSID(); if (string.IsNullOrEmpty(tempwifi) || !tempwifi.Contains(str)) { m_connected = false; } //scan all ssid try to find countpart ssid List<Wlan.WlanAvailableNetwork> ssids = scanSsid(); for(int i = 0; i < ssids.Count; i ++) { Wlan.WlanAvailableNetwork avNetwork = ssids[i]; string tempssid = new String(Encoding.ASCII.GetChars(avNetwork.dot11Ssid.SSID, 0, (int)avNetwork.dot11Ssid.SSIDLength)); //if (string.IsNullOrEmpty(m_cur_profile)) //{ if (tempssid.Contains(str) && !tempssid.Equals(m_last_mobile_softap_profile,StringComparison.CurrentCultureIgnoreCase))//"SW2_NETGEAR-5G" { if (callback != null) { if (!m_connected && callback.CounterpartDiscovered(tempssid)) { m_cur_profile = tempssid; //connect ConnectCouterpart(avNetwork); stop_scan = true; connTimer.Start(); } } break; } //} //else //{ // if (tempssid.Contains(m_cur_profile))//"SW2_NETGEAR-5G" // { // if (callback != null) // { // if (!m_connected && callback.CounterpartDiscovered(m_cur_profile)) // { // //connect // ConnectCouterpart(avNetwork); // stop_scan = true; // connTimer.Start(); // } // } // break; // } //} if (i >= (ssids.Count-1)) { try { m_wlanInterface.Scan(); } catch { } if(m_started) Thread.Sleep(2000); if (!string.IsNullOrEmpty(m_cur_profile)) { m_cur_profile = ""; lock (locker) m_connected = false; //callback clean mobile softap context if (callback != null) callback.ConnFailed(); if (!string.IsNullOrEmpty(m_cur_wifi_ssid)) { m_wlanInterface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Infrastructure, m_cur_wifi_ssid); } } } } } }); threadHand1.Start(); }
static void checkConnection() { #if(!DEBUG) try { #endif if (wifi == null) { foreach (WlanClient.WlanInterface wlanInt in wlan.Interfaces) { if (wlanInt.InterfaceState == Wlan.WlanInterfaceState.Connected) { Wlan.Dot11Ssid ssid = wlanInt.CurrentConnection.wlanAssociationAttributes.dot11Ssid; string strSSID = new String(Encoding.ASCII.GetChars(ssid.SSID, 0, (int)ssid.SSIDLength)); if (strSSID.ToLower() == "ppccstudents") { wifi = wlanInt; wifi.WlanNotification += new WlanClient.WlanInterface.WlanNotificationEventHandler(wifi_WlanNotification); sleepTime = 10000; isConnected = true; } } } } else { if (wifi.InterfaceState == Wlan.WlanInterfaceState.Connected) { Wlan.Dot11Ssid ssid = wifi.CurrentConnection.wlanAssociationAttributes.dot11Ssid; string strSSID = new String(Encoding.ASCII.GetChars(ssid.SSID, 0, (int)ssid.SSIDLength)); if (strSSID.ToLower() == "ppccstudents") { sleepTime = 10000; isConnected = true; } } else { isConnected = false; authenticated = false; sleepTime = 1000; } } #if(!DEBUG) } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("!-- Unable to query the Wireless NIC. Shutting down --!"); Console.ForegroundColor = ConsoleColor.Gray; closing = true; } #endif }