using NativeWifi;
using System.Net.NetworkInformation;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Wifi
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static string GetStringForSSID(Wlan.Dot11Ssid ssid)
{
return Encoding.ASCII.GetString(ssid.SSID, 0, (int)ssid.SSIDLength);
}
private void Form1_Load(object sender, EventArgs e)
{
WlanClient client = new WlanClient();
foreach (WlanClient.WlanInterface wlanIface in client.Interfaces)
{
Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList(0);
foreach (Wlan.WlanAvailableNetwork network in networks)
{
if (network.dot11DefaultCipherAlgorithm == Wlan.Dot11CipherAlgorithm.WEP)
{
textBox1.Text = ("Found WEP network with SSID {0}." + GetStringForSSID(network.dot11Ssid));
}
}
foreach (Wlan.WlanProfileInfo profileInfo in wlanIface.GetProfiles())
{
string name = profileInfo.profileName;
string xml = wlanIface.GetProfileXml(profileInfo.profileName);
}
string profileName = "CheeseCake";
string mac = "52544131303235572D454137443638";
string key = "hello";
string profileXml = string.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"
http://www.microsoft...LAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><hex>{1}</hex><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><MSM><security><authEncryption><authentication>open</authentication><encryption>WEP</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);
wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, true);
wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName);
foreach (Wlan.WlanAvailableNetwork network in networks)
{
textBox1.Text = textBox1.Text + GetStringForSSID(network.dot11Ssid) + Environment.NewLine;
}
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) //Get Mac adress
{
string MACAddress = nic.GetPhysicalAddress().ToString();
textBox1.Text = textBox1.Text + MACAddress + Environment.NewLine;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}