[英]How to connect to WiFi?
我正在嘗試使用 python 連接到 WiFi 網絡,但到目前為止還沒有找到任何方法......
from wireless import Wireless
wire = Wireless()
wire.connect(ssid=name,password=pass)
沒有運氣
'Exception: Unable to auto-detect the network interface.'
另一種嘗試:
import winwifi
name='xxxx'
password='11111'
try:
winwifi.WinWiFi.connect(name,password)
print('t')
except Exception as e:
print(e)
沒有錯誤,沒有什么,但沒有連接,仍然沒有。
我試過:
import winwifi
import time
import os
def createNewConnection(name, SSID, password):
config = """<?xml version=\"1.0\"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
<name>"""+name+"""</name>
<SSIDConfig>
<SSID>
<name>"""+SSID+"""</name>
</SSID>
</SSIDConfig>
<connectionType>ESS</connectionType>
<connectionMode>auto</connectionMode>
<MSM>
<security>
<authEncryption>
<authentication>WPA2PSK</authentication>
<encryption>AES</encryption>
<useOneX>false</useOneX>
</authEncryption>
<sharedKey>
<keyType>passPhrase</keyType>
<protected>false</protected>
<keyMaterial>"""+password+"""</keyMaterial>
</sharedKey>
</security>
</MSM>
</WLANProfile>"""
command = "netsh wlan add profile filename=\""+name+".xml\""+" interface=Wi-Fi"
with open(name+".xml", 'w') as file:
file.write(config)
os.system(command)
# function to connect to a network
def connect(name, SSID):
command = "netsh wlan connect name=\"" + name + "\" ssid=\"" + SSID + "\" interface=Wi-Fi"
os.system(command)
但我只能連接到已知網絡
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.