gpt4 book ai didi

c# - 如何在 wpf 中使用简单的 wifi 连接到 wifi?

转载 作者:行者123 更新时间:2023-12-02 00:44:03 25 4
gpt4 key购买 nike

我正在尝试使用 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);

}
}
}

see the change in zshnu after I tried this code

如果我有像这样硬编码的密码,我就不能传递密码

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com