0

I'm trying to connect to WiFi network with python and haven't found any way so far...

from wireless import Wireless

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

and no luck

'Exception: Unable to auto-detect the network interface.'

Another attempt:

import winwifi


name='xxxx'
password='11111'


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

No error, no nothing, but not connecting and still nothing.

martineau
  • 119,623
  • 25
  • 170
  • 301
sergio art
  • 39
  • 3
  • May need more information. What's your computer model, wireless card, Windows version, etc. // Can you connect to Wi-Fi manually? – user202729 Oct 22 '21 at 23:55
  • What operating system are you targeting? Something like networking is going to be inherently OS-dependent. – Jonathon Reinhart Oct 22 '21 at 23:55
  • im working with windows 10, but im still trying to avoid using os. and yes i can coneect mamually – sergio art Oct 22 '21 at 23:58
  • Have you looked at the answers to [How to connect to WiFi network on Windows?](https://stackoverflow.com/questions/56721759/how-to-connect-to-wifi-network-on-windows) – martineau Oct 23 '21 at 00:12

1 Answers1

0

i tried:

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)

but i can connect only to known networks

sergio art
  • 39
  • 3