简体   繁体   中英

Easiest way to connect to wifi in python

我想使用 python 连接到 wifi,包括新的和以前的连接,也可以在任何 os 中,例如 raspberry pie、windows 等。任何人都可以告诉我如何做到这一点,而且我想只使用 ssid 和密码连接到 wifi,我不知道如果需要,没有 wifi 网络的接口,只有 ssid 和密码。

You could use wireless :

pip install wireless

from wireless import Wireless

wire = Wireless()
wire.connect(ssid=name,password=pass)

winwifi :

pip install winwifi (On windows only)

import winwifi


name='xxxx'
password='11111'


try:
    winwifi.WinWiFi.connect(name,password)
    print('t')
except Exception as e:
    print(e)

or wifi :

pip install wifi

from __future__ import print_function

from wifi import Cell, Scheme

# get all cells from the air
ssids = [cell.ssid for cell in Cell.all('wlan0')]

schemes = list(Scheme.all())

for scheme in schemes:
    ssid = scheme.options.get('wpa-ssid', scheme.options.get('wireless-essid'))
    if ssid in ssids:
        print('Connecting to %s' % ssid)
        scheme.activate()
        break

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM