joshvillbrandt / wireless

A dead simple, cross-platform Python library to connect to wireless networks.
https://pypi.org/project/wireless/
Apache License 2.0
83 stars 42 forks source link

Windows support #2

Open techtonik opened 9 years ago

techtonik commented 9 years ago

Awesome idea. It kicked me to search how to do that in Windows - http://www.hanselman.com/blog/HowToConnectToAWirelessWIFINetworkFromTheCommandLineInWindows7.aspx

joshvillbrandt commented 9 years ago

Nice! Thanks for the link.

I don't have any immediate need for this myself, but I'll happily consider a pull request if you'd like to submit one.

Copying the meat of that post here for posterity:

netsh wlan connect ssid=YOURSSID name=PROFILENAME

# What's a profile? It's the only thing required. You can see them with:

C:\>netsh wlan show profile

# Profiles on interface Wireless Network Connection: 
# ...snip.. 
# User profiles 
# ------------- 
#     All User Profile     : Clear Spot b0e 
#     All User Profile     : HANSELMAN-N 
#     All User Profile     : Quiznos

# These are the same ones that you see in the wireless networks dialog...

# Manage Wireless Networks 

# You can set these up and refer to them by name from the command line, or a batch file, etc. Nice to do for the places you are regularly.

# If you have multiple wireless cards (What's wrong with you!?) then you have to be more specific:

netsh wlan connect ssid=YOURSSID name=PROFILENAME interface="WIRELESS NETWORK CONNECTION"

# And of course, you can
netsh wlan disconnect

# And include the interface optionally, for multiple interfaces. Additionally, interesting things can be seen with

netsh wlan dump

# This is nice because you can

netsh wlan dump > myconfig.txt

on one machine and then later on another machine

netsh exec myconfig.txt
techtonik commented 9 years ago

I am not sure how to handle the "Profiles" stuff. What should be the logic behind wireless.connect(ssid='ssid', password='password')?

  1. How to create profile to connect to if it doesn't exist?
  2. How to find one for the given SSID?
  3. How to select correct profile if there are multiple ones for the given SSID?
joshvillbrandt commented 9 years ago

Looks like you figured out 2 and 3 in the pull request. The answer to 1 (and 2 and 3) are driver specific. (It looks like the program/driver that you are interfacing with here is netsh.) Since I don't have experience with netsh, I'm not sure how to create new profiles, but it would definitely be a nice feature to have. All of the existing drivers in this package support connecting to previously unconfigured wireless connections.

techtonik commented 9 years ago

During work on 6b59fc45a06e I found that Windows seems to support multiple SSID per profile. It may be worthy to create some PythonWireless profile. It may to connect faster, because querying all profiles for their SSID is slow. I still don't know how to connect to some unknown SSID from command line and set password.

techtonik commented 9 years ago

Found a faster strategy to query available profiles - read files from C:\ProgramData\Microsoft\Wlansvc\Profiles\Interfaces

Windows has no way to decrypt WiFi password under user account - needs to do this from LocalSystem. I see the way to create new profile with netsh wlan add profile, but no way so far to connect to SSID with explicitly mentioned password.

techtonik commented 9 years ago

I see no way to configure SSID for existing profile on Vista. =/

techtonik commented 9 years ago

One netsh wlan add profile can be used to load .XML files, but it need password to be encrypted somehow.

techtonik commented 9 years ago

Ok, it might be possible to create XML profile with encrypted password https://stackoverflow.com/questions/2374331/python-win32crypt-cryptprotectdata-difference-between-2-5-and-3-1 and add it if it doesn't exist of if password is different. Need to check if encryption is valid.

techtonik commented 9 years ago

Looks like this trick with <protected>false</protected> might work. Needs testing though. https://superuser.com/questions/133097/netsh-wlan-add-profile-not-importing-encrypted-passphrase

joshvillbrandt commented 9 years ago

Nice! Looks like you have all of the pieces to get this to work. This will be similar to my existing "wpa_supplicant" adapter in that a temporary file needs to be created in order to establish the profile.

What versions of Windows are you testing on? I would say Windows 7 and up would be good to support. I wouldn't worry about Vista.

techtonik commented 9 years ago

Vista is my only, and most likely the last Windows. =)

techtonik commented 7 years ago

As I promised, Vista was my last Windows, so don't expect me to get back to it. )