需要下载SimpleWifi包,引用之后代码可用
//(全局变量)Wifi wifia;
wifia = new Wifi();
var g = wifia .GetAccessPoints();
foreach (var item in g)
{
if (item.Name == "wifi名称")
{
AuthRequest ar = new AuthRequest(item);
ar.Password = "wifi密码";
item.Connect(ar);
if (!item.Connect(ar))
{
MessageBox.Show("网络连接失败");
}
else
{
MessageBox.Show("网络连接成功");
}
}
}
断开wifi的方法
wifia.Disconnect();