Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature for retrieving current connected wifi network and its network strength #898

Open
sanchitsharma opened this issue Sep 30, 2016 · 7 comments

Comments

@sanchitsharma
Copy link

It can be retrieved easily in linux and OS X. Would like to work on this. @giampaolo - What do you think?

@giampaolo
Copy link
Owner

Interesting. It's better we discuss the API first though. What into are we able to retrieve exactly? Possibly we should also consider other platforms, Windows at the very least, but if have looked into linux and osx that's fine.

@sanchitsharma
Copy link
Author

We will be able to retrieve the SSID of the wireless connection on which the device is connected and its current RSSI value. The api can also be expanded to retrieve all discovered wireless ssid's and their rssi values but I would like to propose doing that in an other request maybe.

I have not looked into windows. Will try to do that as well.

@giampaolo
Copy link
Owner

On linux, iwconfig command gives an idea on what information such an API could return:

~/svn/psutil $ iwconfig 
wlp3s0    IEEE 802.11abgn  ESSID:"netis"  
          Mode:Managed  Frequency:2.437 GHz  Access Point: 04:8D:38:BC:BE:DD   
          Bit Rate=150 Mb/s   Tx-Power=22 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:on
          Link Quality=65/70  Signal level=-45 dBm  
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:4790   Missed beacon:0

lo        no wireless extensions.

vboxnet0  no wireless extensions.

The way I see it, we could have a new net_wifi_stats() function, returning a dict similar to https://pythonhosted.org/psutil/#psutil.net_if_stats.
At first I would start returning only the most important info, with the eventuality that we'll later add support for more platforms.
From the info above, the interesting stuff looks like being:

  • network (ESSID)
  • frequency
  • accpoint_macaddr
  • bitrate

I don't know anything about wifi protocols but information regarding the power of the wifi signal would be nice to have. In there I see "link quality" and "signal level", but I'm not sure exactly what they represent.

Have you already investigate how to extract this info on Linux and OSX?

@giampaolo
Copy link
Owner

@sanchitsharma
Copy link
Author

Link quality is detailed here - http://superuser.com/a/203239.
For linux I was planning to use iwconfig. For OS X it some metrics can be retrieved via -

Sanchits-MacBook-Pro:~ sanchitsharma$ /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I
     agrCtlRSSI: -60
agrExtRSSI: 0
    agrCtlNoise: -95
    agrExtNoise: 0
          state: running
        op mode: station 
     lastTxRate: 73
        maxRate: 72
lastAssocStatus: 0
    802.11 auth: open
      link auth: wpa-psk
          BSSID: c8:3a:35:1d:cf:28
           SSID: Neo
            MCS: 7
        channel: 5

But this does not give bit rate and frequency, I could not find anything to give bit rate and frequency on OSx. (I was planning to give only SSID, BSSID (mac) and RSSI (agrCtlRSSI)).

I have not used windows api in python before. I think I would have to use that to use this on Windows. That would be doable.

@giampaolo
Copy link
Owner

giampaolo commented Oct 3, 2016

As for Linux (or any platform) we should not parse iwconfig command output but instead do what iwconfig does. I assume that's either reading from /proc filesystem or use C syscalls.
iwconfig source code is here:
http://www.labs.hpe.com/personal/Jean_Tourrilhes/Linux/Tools.html#latest

@himanshub16
Copy link
Contributor

How about using the Network Manager? nmcli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants