在 C# 中管理无线网络连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/285665/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 21:40:17  来源:igfitidea点击:

Managing wireless network connection in C#

c#.netnetworkingwireless

提问by user37149

We've got a WinForms app written in C# that has a very custom GUI. The user is not allowed to run any other applications and the user cannot go into the OS (WinXP Pro) at all. We're planning on allowing the user to connect to available wireless networks. We're going to have to create a configuration screen that displays available networks (by SSID) and allows the user to connect. While connected we want to display signal strength.

我们有一个用 C# 编写的 WinForms 应用程序,它有一个非常自定义的 GUI。不允许用户运行任何其他应用程序,用户根本无法进入操作系统(WinXP Pro)。我们计划允许用户连接到可用的无线网络。我们将不得不创建一个显示可用网络(按 SSID)并允许用户连接的配置屏幕。连接时,我们希望显示信号强度。

Are there any existing components that provide this capability? I haven't found anything but this.

是否有任何现有组件提供此功能?除了这个,我什么也没找到。

I can set the TCP/IP settings using WMI, but it's the wireless stuff that I need a direction on.

我可以使用 WMI 设置 TCP/IP 设置,但我需要指导的是无线方面的内容。

Many thanks!

非常感谢!

Matt

马特

采纳答案by MusiGenesis

Managed Wifi APIshould work.

托管 Wifi API应该可以工作。

This might not be ideal - you have XP, which is good, but you would have to deploy a hotfix. I'd go for it, because all the wifi code I've dealt with (for the Compact Framework) is hideous. This code is as simple as could be.

这可能并不理想 - 您有 XP,这很好,但您必须部署修补程序。我会去做,因为我处理过的所有 wifi 代码(对于 Compact Framework)都是可怕的。这段代码尽可能简单。

Their sample code doesn't include reading the signal strength, though, and I'm not sure if the Native wifi API provides that. I have written C# code that gets the wireless signal strength, but it did this by PInvoking into a manufacturer-specific DLL available only on their devices. It may be that you'll have to do something similar to get the wireless strength from your PC's wireless card (and that may be why that functionality is not available in an all-purpose API).

不过,他们的示例代码不包括读取信号强度,而且我不确定 Native wifi API 是否提供了这一点。我已经编写了获取无线信号强度的 C# 代码,但它是通过 PInvoking 到制造商特定的 DLL 中来实现的,该DLL 仅在他们的设备上可用。可能您必须执行类似的操作才能从 PC 的无线网卡获得无线强度(这可能就是该功能在通用 API 中不可用的原因)。

回答by sudheer

It is possible to connect available wireless networks using native wifi.

可以使用本机 wifi 连接可用的无线网络。

http://www.codeproject.com/KB/gadgets/SignalStrenghth.aspx

http://www.codeproject.com/KB/gadgets/SignalStrenghth.aspx

Check the link, Which was developed by me.

检查链接,这是由我开发的。

回答by Robin Andersson

I wrote a library which is a layer of abstraction above Managed Wifi, it is a bit more convenient to use. You can find it on GitHub.

我写了一个库,在Managed Wifi之上抽象了一层,使用起来方便一些。您可以在 GitHub 上找到它