private void ResetXml_button_Click(object sender, EventArgs e) { //重新创建xml文件 XmlOP reset = new XmlOP(); reset.creXml(); }
private void AutoConnect_Load(object sender, EventArgs e) { wifiName = wifi.ScanSSID(); //获取wifi名 foreach (WIFISSID SSID in wifiName) { WifiName_comboBox.Items.Add(SSID.SSID); //显示 } if (!IsXML()) { XmlOP creXml = new XmlOP(); creXml.creXml(); } getStyle(); }
public Boolean ConnectToSSID() { try { int Desc = 0; //string mac = StringToHex(profileName); //string key = "1213141516"; //string profileXml = string.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><hex>{1}</hex><name>New{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><MSM><security><authEncryption><authentication>open</authentication><encryption>none</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>networkKey</keyType><protected>false</protected><keyMaterial>{2}</keyMaterial></sharedKey><keyIndex>0</keyIndex></security></MSM></WLANProfile>", profileName, mac, key); String profileXml = String.Format("<?xml version=\"1.0\" encoding=\"US-ASCII\"?> <WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><name>{0}</name></SSID></SSIDConfig> <connectionType>ESS</connectionType><connectionMode>auto</connectionMode><autoSwitch>false</autoSwitch><MSM><security><authEncryption><authentication>{1}</authentication><encryption>{2}</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>passPhrase</keyType><protected>false</protected><keyMaterial>{3}</keyMaterial></sharedKey></security></MSM></WLANProfile>", targetSSID.SSID, authen, encry, pswd); //string profileXml2 = "<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>Hacker SSID</name><SSIDConfig><SSID><hex>54502D4C494E4B5F506F636B657441505F433844323632</hex><name>TP-LINK_PocketAP_C8D262</name></SSID> </SSIDConfig> <connectionType>ESS</connectionType><connectionMode>manual</connectionMode><MSM> <security><authEncryption><authentication>open</authentication><encryption>none</encryption><useOneX>false</useOneX></authEncryption></security></MSM></WLANProfile>"; targetSSID.wlanInterface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, true); targetSSID.wlanInterface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, targetSSID.SSID); //string myProfileXML = string.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><hex>{1}</hex><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><connectionMode>manual</connectionMode><MSM><security><authEncryption><authentication>open</authentication><encryption>none</encryption><useOneX>false</useOneX></authEncryption></security></MSM></WLANProfile>", profileName, mac); //ssid.wlanInterface.SetProfile(Wlan.WlanProfileFlags.AllUser, myProfileXML, true); //ssid.wlanInterface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName); //Console.ReadKey(); Thread.Sleep(2000); if (InternetGetConnectedState(out Desc, 0)) //有网络连接 { XmlDocument doc = new XmlDocument(); doc.Load("setting.xml"); XmlNodeList nodeList = doc.SelectSingleNode("setting").ChildNodes; foreach (XmlNode xn in nodeList) { XmlElement xe = (XmlElement)xn; if (xe.GetAttribute("ssid").Equals(targetSSID.SSID)) { isAdded = true; } } if (!isAdded) { XmlOP xml = new XmlOP(); xml.addXml(targetSSID.SSID, pswd); } return(true); } } catch (Exception err) { return(false); } return(false); }