awkman / pywifi

A cross-platform module for manipulating WiFi devices.
MIT License
447 stars 154 forks source link

Can't connect no security AP win10 python3 #23

Closed Alrash closed 6 years ago

Alrash commented 6 years ago

I want to connect an AP without serurity setting in my win10. This my code

wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0]
profile = pywifi.Profile()
profile.ssid = 'my-ssid'
profile.auth = const.AUTH_ALG_OPEN
profile.akm.append(const.AKM_TYPE_NONE)
iface.remove_all_network_profiles()
tmp_profile = iface.add_network_profile(profile)
iface.connect(tmp_profile)

However, it doesn't work and the icon of wlan is disconnected.

I use DEBUD mode and then, it shows iface.add_network_profile(profile) return 1206 status, which show profile has some errors.

I change _wifiutil_win.py L338 to L382 into the following code.

    if params.akm[-1] == AKM_TYPE_NONE:
        profile_data['auth'] = auth_value_to_str_dict[params.auth].lower()
        profile_data['encrypt'] = cipher_value_to_str_dict[params.cipher].lower()
        profile_data['mode'] = 'auto'
    else:
        profile_data['auth'] = akm_value_to_str_dict[params.akm[-1]]
        profile_data['encrypt'] = cipher_value_to_str_dict[params.cipher]
        profile_data['mode'] = 'manual'

    profile_data['key'] = params.key

    profile_data['protected'] = 'false'
    profile_data['profile_name'] = params.ssid

    xml = """<?xml version="1.0"?>
    <WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
    <name>{profile_name}</name>
    <SSIDConfig>
        <SSID>
            <name>{ssid}</name>
        </SSID>
    </SSIDConfig>
    <connectionType>ESS</connectionType>
    <connectionMode>{mode}</connectionMode>
    <MSM>
        <security>
            <authEncryption>
                <authentication>{auth}</authentication>
                <encryption>{encrypt}</encryption>
                <useOneX>false</useOneX>
            </authEncryption>
    """

    if params.akm[-1] != AKM_TYPE_NONE:
        xml += """<sharedKey>
                    <keyType>passPhrase</keyType>
                    <protected>{protected}</protected>
                    <keyMaterial>{key}</keyMaterial>
                </sharedKey>
            </security>
        </MSM>
        """
     else:
        xml += """</security>
        </MSM>
        """
awkman commented 6 years ago

@Alrash Thanks for your rich debug information, I fixed this issue in the latest update