作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 simplewifi
连接到 wifi。目前,我尝试过:
Wifi wifi = new Wifi();
// get list of access points
IEnumerable<AccessPoint> accessPoints = wifi.GetAccessPoints();
// for each access point from the list
foreach (AccessPoint ap in accessPoints)
{
Console.WriteLine("ap: {0}\r\n", ap.Name);
//check if SSID is desired
if (ap.Name.StartsWith("z"))
{
//verify connection to desired SSID
Console.WriteLine("connected: {0}, password needed: {1}, has profile: {2}\r\n", ap.Name, ap.IsConnected, ap.HasProfile);
if (!ap.IsConnected)
{
//connect if not connected
Console.WriteLine("\r\n{0}\r\n", ap.ToString());
Console.WriteLine("Trying to connect..\r\n");
AuthRequest authRequest = new AuthRequest(ap);
authRequest.Password = "123456789";
var x=ap.Connect(authRequest);
}
}
}
如果我有像这样硬编码的密码,我就不能传递密码
var password="abc123"
如何传递密码并连接?
此外,connect 方法总是返回 false
,即使我必须在没有密码的情况下连接到 wifi。
最佳答案
你需要设置authRequest.Password = "yourpassword";
在你的 ap.connect(authRequest);
之前
添加来自 https://github.com/DigiExam/simplewifi 的以下 console.write()
放在文件的顶部
using SimpleWifi;
然后在你的函数中
// Wifi object
Wifi wifi = new Wifi();
// get list of access points
IEnumerable<AccessPoint> accessPoints = wifi.GetAccessPoints();
// for each access point from list
foreach (AccessPoint ap in accessPoints){
Console.WriteLine("ap: {0}\r\n", ap.Name);
//check if SSID is desired
if (ap.Name.StartsWith("ardrone_")){
//verify connection to desired SSID
Console.WriteLine("connected: {0}, password needed: {1}, has profile: {2}\r\n", ap.Name, ap.IsConnected, ap.HasProfile);
if (!ap.IsConnected){
//connect if not connected
Console.WriteLine("\r\n{0}\r\n", ap.ToString());
Console.WriteLine("Trying to connect..\r\n");
AuthRequest authRequest = new AuthRequest(ap);
ap.Connect(authRequest);
}
}
}
关于c# - 如何在 wpf 中使用简单的 wifi 连接到 wifi?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45010062/
我是一名优秀的程序员,十分优秀!