如何在 Windows 上连接到 WiFi 网络?

How to connect to WiFi network on Windows?(如何在 Windows 上连接到 WiFi 网络?)
本文介绍了如何在 Windows 上连接到 WiFi 网络?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用 Python 3 编写脚本,但目前所有可用的模块都可以在 Python 2 上运行,这将使我能够搜索无线网络并连接到它们.有没有为此的 Python 3 库?

I am trying to write a script in Python 3 but all modules available today work on python 2 which will enable me to search for wireless networks and to connect to them. Is there any Python 3 library for this?

我为 python 2 尝试的代码

The code I tried for python 2

from wireless import Wireless
wireless = Wireless()
wireless.connect(ssid='ssid', password='password')

这给了我一个错误

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:UsersHimanshu PoddarAppDataLocalProgramsPythonPython36-32libsite-packageswirelessWireless.py", line 23, in __init__
    self._driver_name = self._detectDriver()
  File "C:UsersHimanshu PoddarAppDataLocalProgramsPythonPython36-32libsite-packageswirelessWireless.py", line 50, in _detectDriver
    compare = self.vercmp(ver, "0.9.9.0")
  File "C:UsersHimanshu PoddarAppDataLocalProgramsPythonPython36-32libsite-packageswirelessWireless.py", line 71, in vercmp
    return cmp(normalize(actual), normalize(test))
NameError: name 'cmp' is not defined

但这不起作用,因为它基于 python 2.有什么方法可以使用 Python 3 连接到 wifi

But this is not working since it is based on python 2. Is there any way to connect to a wifi using Python 3

推荐答案

在windows中使用python连接wifi,更好的选择是使用winwifi模块:

To connect wifi using python in windows, the better option is to use the winwifi module:

我建议你在安装 winwifi 之前先安装 plumbum.这是下载铅的链接:https://pypi.org/project/plumbum/

I recommend you to install plumbum before installing winwifi. This is the link to download plumbum: https://pypi.org/project/plumbum/

之后从这里安装winwifi:https://pypi.org/project/winwifi/最好安装在32位的python文件夹中.

After this install winwifi from here:https://pypi.org/project/winwifi/ It's better to install it in 32-bit python folder.

安装后可以通过以下代码查看模块(这是连接之前连接设备的路由器):

After installing you could check the module by the following code (This is to connect router which was connected to the device before):

import winwifi
winwifi.WinWiFi.connect('the_exact_ssid_or_name_of_your_known_wifi_router')

在您的 IDLE 上运行此代码时,您可以看到 wifi 已连接到您的设备.如果您想连接新设备,您可以在添加配置文件后使用代码:

On running this code on your IDLE, you could see that the wifi is connected to your device. If you want to connect a new device you could use the code after adding profile:

import winwifi
winwifi.WinWiFi.addprofile('ssid_of_router')
winwifi.WinWiFi.connect('the_ssid_of_router', 'password')

您可以使用以下命令断开当前 Wifi:

You can disconnect the current Wifi using the command:

import winwifi
winwifi.WinWiFi.disconnect()

这个模块还有更多的命令,尝试探索它们.更多内容请参考 winwifi 文件夹中的 ma​​in.py 文件.

There are many more commands on this module, try to explore them. Just refer to the main.py file in winwifi folder for many more.

这篇关于如何在 Windows 上连接到 WiFi 网络?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Leetcode 234: Palindrome LinkedList(Leetcode 234:回文链接列表)
How do I read an Excel file directly from Dropbox#39;s API using pandas.read_excel()?(如何使用PANDAS.READ_EXCEL()直接从Dropbox的API读取Excel文件?)
subprocess.Popen tries to write to nonexistent pipe(子进程。打开尝试写入不存在的管道)
I want to realize Popen-code from Windows to Linux:(我想实现从Windows到Linux的POpen-code:)
Reading stdout from a subprocess in real time(实时读取子进程中的标准输出)
How to call type safely on a random file in Python?(如何在Python中安全地调用随机文件上的类型?)