【问题标题】:How to connect to WiFi?如何连接到WiFi?
【发布时间】:2021-10-22 23:49:20
【问题描述】:

我正在尝试使用 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)

没有错误,没有什么,但没有连接 还是什么都没有。

【问题讨论】:

  • 可能需要更多信息。你的电脑型号、无线网卡、Windows版本等//你可以手动连接Wi-Fi吗?
  • 您的目标是什么操作系统?像网络这样的东西本质上是依赖于操作系统的。
  • 我正在使用 Windows 10,但我仍然试图避免使用 os.是的,我可以连接哺乳动物

标签: python windows networking wifi


【解决方案1】:

我试过了:

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)

但我只能连接到已知网络

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-07
    • 2023-04-02
    • 2018-02-25
    相关资源
    最近更新 更多