awkman / pywifi

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

Basic functions with PyWiFi.intefaces not working. (Python 2.7.12 - Win 10) #8

Closed wgaylord closed 7 years ago

wgaylord commented 7 years ago

I am on Windows10 with python 2.7.12

`>>> wifi.interfaces()[0].scan()

wifi.interfaces()[0].scan_results <bound method Interface.scan_results of <pywifi.iface.Interface instance at 0x0313CAF8>> wifi.interfaces()[0].scan_results() Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\site-packages\pywifi\iface.py", line 39, in scan_results return wifiutils.scan_results(self.raw_obj) File "C:\Python27\lib\site-packages\pywifi\win\wifiutils.py", line 30, in scan_results network['ssid'] += "%c" % bsses[i].dot11Ssid.ucSSID[j] IndexError: string index out of range wifi.interfaces()[0].status <bound method Interface.status of <pywifi.iface.Interface instance at 0x0313CAF8>> wifi.interfaces()[0].status() Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\site-packages\pywifi\iface.py", line 74, in status return wifiutils.status(self.raw_obj) File "C:\Python27\lib\site-packages\pywifi\win\wifiutils.py", line 186, in status data = wifiapi.PDWORD() AttributeError: 'module' object has no attribute 'PDWORD'`

is the error.

awkman commented 7 years ago

Did you try running pywifi in python3 env? Because I wrote pywifi in python3 env, I am not quite sure it can run on python2 env now

wgaylord commented 7 years ago

Well.. I was using py2

wgaylord commented 7 years ago

I'm mostly use py2 because that's what most people use. (Like even most professionals use it over py3)

On Oct 6, 2016 11:13 AM, "Awk" notifications@github.com wrote:

Did you try running pywifi in python3 env? Because I wrote pywifi in python3 env, I am not quite sure it can run on python2 env now

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/awkman/pywifi/issues/8#issuecomment-252011706, or mute the thread https://github.com/notifications/unsubscribe-auth/ACCNyfWJaY1xZ7547kLSrGcXC-LDyMWNks5qxR42gaJpZM4KOTdo .

wgaylord commented 7 years ago

Any idea if this can be looked into?

awkman commented 7 years ago

After I fix issue #10, I will try to test pywifi under py2.7 and evaluate is it possible to support py2.7. I am not quite sure about how many py3 features now pywifi depends on...

die-gans commented 7 years ago

I think what needs to be considered is the way python 2.7 handles imports compared to python 3.X as well as some syntax changes. Might not even be worth going to 2.7 as the differences between the two are quite large.

Heres a handy little article: http://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html

wgaylord commented 7 years ago

So should I just continue searching for a py2.7 compatible wifi lib and just close this? Because I need to stay on 2.7 (I have many reasons)

die-gans commented 7 years ago

Up to awkman I suppose, whats your aim with the use of this lib?

@chibill I'm currently working on a project which uses the win32api. There might be a few issues with syntax but have a read: https://github.com/thepizzagui/wifiSwap/blob/master/wlanAPI.py

wgaylord commented 7 years ago

Well I am mostly interested in being able to get the wifi BSSID around me. So I can make a script to auto connect to some APs. (Like the free ones at McDonalds.)

die-gans commented 7 years ago

Im working on something similar as a small project. At its current version the code I linked is quite messy however it gets bssids and ssids and stores then in a dict for easy access. Probably works for 2.7

wgaylord commented 7 years ago

I can make the current version ( Just now downloaded from repo) load and work by just changing the way that the metaclass is defined.. (Do it the python 2 why that is still correct for python 3).

And it appears to work. (Scan works and scan_results works. Still testing other stuff)

wgaylord commented 7 years ago

Okay the network_profiles works (Sort of one of the networks around me has a key type that errors it out. WPA2) I also know how to patch it so that status works (Python 2.7 ctypes.wintypes does not have PDWORD but if you copy the line that defines it from cytpes.wintypes on python 3 it works)

awkman commented 7 years ago

@chibill Good news!! Is it convenient for you to send a PR after you finish the modification and test under python 2.7? I would learn from the patch and try to merge it into pywifi!!

wgaylord commented 7 years ago

I can. Not sure about the strange stuff with WPA2 it seems odd. (But that exists in. Python3)

wgaylord commented 7 years ago

I mean the problem with that exists in py3 also

awkman commented 7 years ago

Could you share the error message?

wgaylord commented 7 years ago

I know why its erroring. https://github.com/awkman/pywifi/blob/master/pywifi/win/wifiutil.py#L43-L47 Does not contain a value with the key WPA2 (Which is the auth type my schools wifi uses when looking at the xml file)

`

WPA2
                            <encryption>AES</encryption>
                            <useOneX>true</useOneX>
                    </authEncryption>`

Thats the area you use to find the auth type.

Which actually acording to windows its using WPA@-Enterprise for a Security type.

Actually Traceback is.

Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\site-packages\pywifi\iface.py", line 82, in network_profiles profiles = self._wifi_ctrl.network_profiles(self._raw_obj) File "C:\Python27\lib\site-packages\pywifi\win\wifiutil.py", line 364, in network_profiles profile['key_mgmt'].append(key_mgmt_dict[key_mgmt]) KeyError: u'WPA2'

awkman commented 7 years ago

Oh... I don't start to plan to support other key mgmt type now. That's because I don't have the environment to test them. I think we should add one more key mgmt type like 'OTHER' to skip it.

wgaylord commented 7 years ago

True.. I wonder how you could handle them. (Why do you use a dict there anyways?)

Could we not just keep what ever was returned by the xml as a string? For both auth and also encryption?

awkman commented 7 years ago

I didn't consider other auth type at that moment, so I adopted dict here. I want a unified expression for key mgmt while getting the scan result or assigning the ap profile. So, I think keep them as integers is better.

wgaylord commented 7 years ago

Okay. Currently they are only used for network_profiles. And adapting them to use the string directly actually removes so if statements from the add_network_profile. (Would only need to check for if its open)

I will leave that alone as I am just interested in getting it python 2 compatible.

awkman commented 7 years ago

@chibill Thanks for your idea and PR, I merge your PR now.

wgaylord commented 7 years ago

Okay. So this can be closed now. :)