6

I'm looking to see if there is a way to connect or disconnect to a wireless network in python, preferably a way that would work for both public and secured networks if I supplied the password. If I can configure the options about wireless, that would be an added bonus (ex. see all networks in range, see information about networks in range (like encryption type)). I run a windows computer, so I see many answers to this question in Linux, or other operating systems, but none in windows. Thanks in advance.

Tom
  • 846
  • 5
  • 18
  • 30

1 Answers1

4

You'll probably have to use one of the DLLs in windows for that. Using ctypes you can get access to the win32 API from Python.

It looks like the functions from wlanapi.dll, starting with WlanOpenHandle and WlanEnumInterfaces might do what you want.

Edit: For example code, see the accepted answer to this.

Community
  • 1
  • 1
Roland Smith
  • 42,427
  • 3
  • 64
  • 94
  • Well, could you explain how I could do that? I didn't see anything on making enums in ctypes and it required definition of an enum type "WLAN_CONNECTION_MODE". – Tom Aug 27 '12 at 11:43
  • An `enum` in C is basically just a shortcut for making a list of integer constants, starting with 0 and incrementing with 1, unless specified otherwise. So if you look at http://msdn.microsoft.com/en-us/library/windows/desktop/ms706844%28v=vs.85%29.aspx, `wlan_connection_mode_profile` is 0, `wlan_connection_mode_temporary_profile` is 1, up to `wlan_connection_mode_invalid` is 5. – Roland Smith Aug 27 '12 at 12:00