用python或linux终端连接wifi

I.e*_*yed 5 python linux networking wifi raspberry-pi

我正在尝试通过 python 和 linux 终端连接到 wifi,但在这两种情况下它都不适合我。

对于 python,我正在使用这个库https://wifi.readthedocs.org/en/latest/scanning.html 扫描并保存方案工作正常,但是每当我输入这行代码时,scheme.activate() 却没有输出

任何想法图书馆有什么问题以及您之前是否使用过它?

我还尝试使用 CLI 连接到 WiFi 网络。我用谷歌搜索,发现我应该做这三个语句 1- iwlist wlan0 scan // 扫描无线网络 2- iwconfig wlan0 essid "Mywirelessnetwork" // 与网络关联 3- dhclient wla0 // 获得 UP

每当我执行第 2 步然后检查 iwconfig wlan0 时,我发现无线接口没有关联!!

有任何想法吗 ???

我想要做的是拥有一个连接到 wifi 的方法库,最好是通过 python 函数或库,并在 raspberry PI 上进行测试,因为我正在构建一些需要网络连接的应用程序。

Ham*_*FzM 1

首先尝试查看这些链接: http://packages.ubuntu.com/raring/python-wicd https://wifi.readthedocs.org/en/latest/

如果你想通过 python 使用 bash 命令,请尝试以下代码:

from subprocess import Popen, STDOUT, PIPE
from time import sleep

handle = Popen('netsh wlan connect wifi_name', stdout=PIPE, stdin=PIPE, shell=True,  stderr=STDOUT)

sleep(10)

handle.stdin.write(b'wifi_password\n')
while handle.poll() == None:
    print handle.stdout.readline().strip()  # print the result
Run Code Online (Sandbox Code Playgroud)

但要确保你在Linux中以超级用户身份运行但在Windows中没有问题。