树莓派自动连接wifi的python脚本 [英] python script for RaspberryPi to connect wifi automatically
问题描述
我想用 RaspberryPi 操作 WiFi dongle,(就像一个没有内置 WiFi 的 CPU).我需要编写一个 python 脚本来自动扫描 WiFi 网络,并且需要使用已知的 SSID 和密码自动建立连接.
I want to operate a WiFi dongle with RaspberryPi, (it's like a CPU without built-in WiFi). I need to write a python script which automatically scan for WiFi networks and a connection need to be automatically established with known SSID and password.
这意味着我需要从文件中提供 WiFi 网络的密码,并且剩下的就是自动扫描和连接了.
This mean that I need to provide the password for the WiFi network from a file, and the remaining thing is to do the scanning and connecting automatically.
我从网上读取了一个包含 WiFi SSID 名称和密码的文件.
I read a file from the Web which contains WiFi SSID name and password.
我需要编写一个脚本来扫描并列出当前的网络,并将其与文件中的 SSID 进行匹配,并进一步自动创建与该已知网络的连接.
I need to write a script which scan and list current networds and match it to the SSID from the file and further to automatically create the connection to this known network.
RaspberryPi 操作系统:Rasbian
RaspberryPi OS: Rasbian
推荐答案
谢谢大家的回答 我做了如下简单的解决方案
Thank you all for your answers i made simple solution like below
def wifiscan():
allSSID = Cell.all('wlan0')
print allSSID # prints all available WIFI SSIDs
myssid= 'Cell(ssid=vivekHome)' # vivekHome is my wifi name
for i in range(len(allSSID )):
if str(allSSID [i]) == myssid:
a = i
myssidA = allSSID [a]
print b
break
else:
print "getout"
# Creating Scheme with my SSID.
myssid= Scheme.for_cell('wlan0', 'home', myssidA, 'vivek1234') # vive1234 is the password to my wifi myssidA is the wifi name
print myssid
myssid.save()
myssid.activate()
wifiscan()
这篇关于树莓派自动连接wifi的python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!