Open techtonik opened 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
I am not sure how to handle the "Profiles" stuff. What should be the logic behind wireless.connect(ssid='ssid', password='password')
?
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.
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.
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.
I see no way to configure SSID for existing profile on Vista. =/
One netsh wlan add profile
can be used to load .XML files, but it need password to be encrypted somehow.
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.
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
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.
Vista is my only, and most likely the last Windows. =)
As I promised, Vista was my last Windows, so don't expect me to get back to it. )
Awesome idea. It kicked me to search how to do that in Windows - http://www.hanselman.com/blog/HowToConnectToAWirelessWIFINetworkFromTheCommandLineInWindows7.aspx