public bool ConnectToOpenNetwork(IAccessPoint accessPoint) { if (!WiFiSupported) { throw new NotSupportedException("No WZC WiFi Adapter detected on this device"); } return(m_wzc.AddPreferredNetwork(accessPoint)); }
/// <summary> /// Conecta a la red adhoc /// Si ocurre algun error se informa en informationNetworkingHandler /// </summary> internal void openWLanConnection() { try { //Revisa si hay un adaptador seleccionado en la configuración if (netData.NetworkAdapter == null) { throw new Exception("no hay un adaptador de red seleccionado"); } INetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces(); foreach (INetworkInterface networkInterface in networkInterfaces) { if (netData.NetworkAdapter.Name.Equals(networkInterface.Name)) { WirelessZeroConfigNetworkInterface adapter = (WirelessZeroConfigNetworkInterface)networkInterface; adapter.AddPreferredNetwork(netData.AdhocNetworkName, false, "", 1, AuthenticationMode.Open, WEPStatus.WEPDisabled, null); adapter.ConnectToPreferredNetwork(netData.AdhocNetworkName); connectionState = WifiConnectionState.WAINTING; break; } } } catch (ThreadAbortException e) { throw e; } catch (Exception e) { wifiInformation("error " + e.Message); } }
void apConnectMenuItem_Click(object sender, EventArgs e) { AccessPoint ap = m_selectedItem.Tag as AccessPoint; WirelessZeroConfigNetworkInterface wzc = Presenter.WirelessInterface as WirelessZeroConfigNetworkInterface; if (apConnectMenuItem.Text == "Connect") { // is it in our preferred list? If so, add it if ((wzc == null) || (Presenter.IsPreferredAP(ap))) { Presenter.WirelessInterface.Connect(ap.Name); } else { // is it an open network? if (ap.Privacy == 0) { wzc.AddPreferredNetwork(ap.Name, true, (byte[])null, 0, AuthenticationMode.Open, WEPStatus.WEPDisabled, null); } else { // TODO: MessageBox.Show("Need to get WEP key from user", "Not Implemented"); } } } else { } }
static void Main() { WirelessZeroConfigNetworkInterface wzc = null; foreach (var intf in NetworkInterface.GetAllNetworkInterfaces()) { if (intf is WirelessZeroConfigNetworkInterface) { wzc = (WirelessZeroConfigNetworkInterface)intf; break; } } if (wzc == null) { Output("No WZC adapter found"); Debugger.Break(); return; } int PAD = 20; foreach (var ap in wzc.PreferredAccessPoints) { Output("AP: " + ap.Name); Output("\tPrivacy: ".PadRight(PAD, ' ') + ap.Privacy.ToString()); Output("\tSignal: ".PadRight(PAD, ' ') + ap.SignalStrength); Output("\tChannel: ".PadRight(PAD, ' ') + ap.Channel); } foreach (var ap in wzc.NearbyAccessPoints) { Output("AP: " + ap.Name); Output("\tPrivacy: ".PadRight(PAD, ' ') + ap.Privacy.ToString()); Output("\tSignal: ".PadRight(PAD, ' ') + ap.SignalStrength); Output("\tChannel: ".PadRight(PAD, ' ') + ap.Channel); if ((ap.Privacy == WEPStatus.WEPEnabled) && (ap.Name.ToLower().StartsWith("opennetcf"))) { continue; string key = "badf00d"; wzc.AddPreferredNetwork(ap.Name, true, key, 1, AuthenticationMode.Shared, WEPStatus.WEPEnabled, null); } else if (ap.Privacy == WEPStatus.TKIPEnabled) { //continue; string key = "sharedkey"; EAPParameters eap = null; wzc.AddPreferredNetwork(ap.Name, true, key, 1, AuthenticationMode.WPAPSK, WEPStatus.TKIPEnabled, eap); } else if (ap.Privacy == WEPStatus.AESEnabled) { //continue; string key = "sharedkey"; EAPParameters eap = null; wzc.AddPreferredNetwork(ap.Name, true, key, 1, AuthenticationMode.WPA, WEPStatus.AESEnabled, eap); } } Output("Press <ENTER> to continue"); Console.ReadLine(); // Application.Run(new Form1()); }
public void PreferredOpenInfrastructureAPTest(WirelessZeroConfigNetworkInterface wzc) { List <string> preferredAPs = new List <string>(); // get a list of available adapters INetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); if (interfaces.Length <= 0) { Assert.Fail("No interfaces available to test"); } bool wzcFound = false; // find the WZC adapter foreach (INetworkInterface intf in interfaces) { if (intf is WirelessZeroConfigNetworkInterface) { // run the test wzcFound = true; // get a list of preferred APs foreach (NI.AccessPoint ap in wzc.PreferredAccessPoints) { preferredAPs.Add(ap.Name); } // remove them all foreach (string ssid in preferredAPs) { if (!wzc.RemovePreferredNetwork(ssid)) { Assert.Fail("Failed to remove AP " + ssid); } } // make sure the list really got emptied if (wzc.PreferredAccessPoints.Count > 0) { Assert.Fail("Failed to drop all preferred APs"); } // make sure we have a nearby AP NI.AccessPointCollection nearbyAPs = wzc.NearbyAccessPoints; if (nearbyAPs.Count <= 0) { // try twice, in case the adapter was not initialized System.Threading.Thread.Sleep(100); nearbyAPs = wzc.NearbyAccessPoints; if (nearbyAPs.Count <= 0) { Assert.Fail("No nearby APs found"); } } bool nearbyFound = false; List <string> nearbyNames = new List <string>(); foreach (NI.AccessPoint ap in nearbyAPs) { if (nearbyNames.Contains(ap.Name)) { // we can't add two APs with the same name (and different physical addresses) continue; } nearbyNames.Add(ap.Name); if (ap.InfrastructureMode == NI.InfrastructureMode.Infrastructure) { if (ap.Privacy == 0) { // we have found an open, infrastructure AP nearbyFound = true; if (!wzc.AddPreferredNetwork(ap.Name, false, null, 1, NI.AuthenticationMode.Open, NI.WEPStatus.WEPDisabled, null)) { Assert.Fail("Failed to add AP named " + ap.Name); } } } } if (!nearbyFound) { Assert.Fail("No nearby APs found"); } // now remove them all again (to ensure we've actually removed something - we could have started with none) preferredAPs.Clear(); // get a list of preferred APs foreach (NI.AccessPoint ap in wzc.PreferredAccessPoints) { preferredAPs.Add(ap.Name); } // remove them all foreach (string ssid in preferredAPs) { if (!wzc.RemovePreferredNetwork(ssid)) { Assert.Fail("Failed to remove AP " + ssid); } } Assert.IsTrue(wzc.PreferredAccessPoints.Count == 0, "Failed to remove all preferred APs"); break; } } if (!wzcFound) { Assert.Fail("No WZC Adapter found"); } }