Giter Site home page Giter Site logo

access_points's Introduction

access_points

Build Status PyPI PyPI

Scan your WiFi and get access point information and signal quality.

Works on multiple platforms: Windows/OSX/Linux.

Installation

pip install access_points

On linux systems you might want to install nmcli (recommended) or iwlist:

apt-get install network-manager # Ubuntu
pacman -S networkmanager        # Arch Linux

Usage

In Python

from access_points import get_scanner
wifi_scanner = get_scanner()
wifi_scanner.get_access_points()
# [{'bssid': 'XX:XX:XX:XX:XX:XX',
#   'quality': 90,
#   'security': 'WPA2(802.1x,Unrecognized(0)/AES/AES)',
#   'ssid': 'MyWifi1'},
#  {'bssid': 'XX:XX:XX:XX:XX:XX',
#   'quality': 80,
#   'security': 'WPA2(802.1x,Unrecognized(0),FT-802.1x/AES/AES)',
#   'ssid': 'NeighbourWifi1'}]

On command line:

access_points
# [{'bssid': 'XX:XX:XX:XX:XX:XX',
#   'quality': 90,
#   'security': 'WPA2(802.1x,Unrecognized(0)/AES/AES)',
#   'ssid': 'MyWifi1'},
#  {'bssid': 'XX:XX:XX:XX:XX:XX',
#   'quality': 130,
#   'security': 'WPA2(802.1x,Unrecognized(0),FT-802.1x/AES/AES)',
#   'ssid': 'NeighbourWifi1'}]

Using a different device:

Python:

wifi_scanner = get_scanner("wlp2s0")

Command line:

access_points wlp2s0

Tests

This how to run tests:

git clone https://github.com/kootenpv/access_points
cd access_points
python setup.py install
tox

access_points's People

Contributors

atheros1 avatar kdkusano avatar kootenpv avatar koterpillar avatar matthewscholefield avatar pyup-bot avatar rfilmyer avatar rjp avatar sumukh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

access_points's Issues

Feature Request: Include signal strength (in addition to quality)

For iwlist, both of these numbers are present

Cell 02 - Address: 66:33:4B:E0:35:DB
         Quality=27/70  Signal level=-83 dBm 

quality = int(line.split("=")[1].split("/")[0])

# change
quality = int(line.split("=")[1].split("/")[0])
# to
quality, strength = line.split("=")[1:]
quality = int(quality.split("/")[0])
strength = int(strength.split(" ")[0])
# then add
ap = AccessPoint(ssid, bssid, quality, security, strength=strength)

A team that I'm working on is asking for both so it would be nice if both were handled, but I'm not sure about the other platforms.

Windows netsh caches BSSID signal strength for a long time

Issue

The command used for WindowsWifiScanner.get_cmd is:

netsh wlan show networks mode=bssid

It appears Windows uses caching for this command. The result is that the same SSID/BSSID list is printed for a long time (including signal strength). On my machine, the signal strength does not change for more than 1 minute after I physically move around my house. This is not good behavior for scanning applications, e.g. whereami

Possible Solutions

Disable/Enable Interface

Per this solution, disable/enable the wireless interface. Change WindowsWifiScanner.get_cmd to

class WindowsWifiScanner(WifiScanner):

    def get_cmd(self):
        return 'netsh interface set interface name="Wireless Network Connection" admin=disabled && ' + \
            'netsh interface set interface name="Wireless Network Connection" admin=enabled && ' + \
            "sleep 4 && " + \
            "netsh wlan show networks mode=bssid"

Explanation:

  • line 1 and 2: enable and disable interface
  • line 3: wait for interface to come back up (netsh is unavailable until the interface is up)
  • line 4: original

This is not ideal because:

  • Has to execute on administrator command prompt
  • Interface name is different per machine (name="Wireless Network Connection")
  • This is really slow because of the need to sleep

Pure Windows API

Use .NET API to access this information. Looks not fun, I have not investigated (see here and here)

Next steps

I do not think either is an acceptable solution.

Other items to check:

  • Is if there is some hardware settings in Windows to prevent caching?
  • Is there some python interface to the WinAPI that can access the native Wifi info?

SSID hidden

On Windows, python 3.8.3
On Windows 10

wifi_scanner.get_access_points()
[AccessPoint(ssid= , bssid=c0:56:27:e9:e5:12, quality=100, security=WPA2-Personnel)]

wifi_scanner.get_access_points()[0]["ssid"]
' '

image

License?

I was wondering if I could use your code commercially? Are you planning on choosing a license?

"list index out of range"

list index out of range
Line:
                    CFInternet19                   -91  100     Y  -- WPA2(PSK/AES/AES)
Output:
                            SSID BSSID             RSSI CHANNEL HT CC SECURITY (auth/unicast/group)
                    CFInternet19                   -91  100     Y  -- WPA2(PSK/AES/AES)
                    CFInternet19                   -90  36      Y  -- WPA2(PSK/AES/AES)
                         BTWi-fi                   -87  11      Y  -- NONE
                     BTHub6-C3NH                   -87  11      Y  -- WPA2(PSK/AES/AES)
                        BTWifi-X                   -84  1       Y  -- WPA2(802.1x/AES/AES)
                        SKYDAAPC                   -82  1       Y  -- WPA2(PSK/AES/AES)
                   CFL-6BDJ-2.4G                   -61  5,+1    Y  -- WPA(PSK/AES,TKIP/TKIP) WPA2(PSK/AES,TKIP/TKIP)
                        CFL-6BDJ                   -62  64      Y  -- WPA(PSK/AES,TKIP/TKIP) WPA2(PSK/AES,TKIP/TKIP)

On macOS Monterey, 12.0 Beta (21A5522h). Python 3.6.5 |Anaconda, Inc.| (default, Apr 26 2018, 08:42:37)

(It output one of those chunks for every SSID in the list but I don't think it's useful to provide all of them?)

invalid literal for int() with base 10: '-- R'

I get the following error while using whereami.

invalid literal for int() with base 10: '-- R'
Line:
不要亂改網路名稱 -76 6,-1 Y -- RSN(PSK/AES/AES)
Output:
SSID BSSID RSSI CHANNEL HT CC SECURITY (auth/unicast/group)
HuaB5 -92 40 Y -- RSN(PSK/AES/AES)
不要亂改網路名稱 -76 6,-1 Y -- RSN(PSK/AES/AES)

[{"ssid": "HuaB5", "bssid": "", "quality": 16, "security": "RSN(PSK/AES/AES) "}]

Initial Update

Hi 👊

This is my first visit to this fine repo, but it seems you have been working hard to keep all dependencies updated so far.

Once you have closed this issue, I'll create seperate pull requests for every update as soon as I find one.

That's it for now!

Happy merging! 🤖

Crashes if wifi isn't enabled on OS X

If wifi isn't enabled then this program crashes with a message from which it is hard to understand the root cause:

Traceback (most recent call last):
File "/Users/bengtb/.virtualenvs/temp2/bin/access_points", line 11, in
sys.exit(main())
File "/Users/bengtb/.virtualenvs/temp2/lib/python3.5/site-packages/access_points/init.py", line 161, in main
access_points = wifi_scanner.get_access_points()
File "/Users/bengtb/.virtualenvs/temp2/lib/python3.5/site-packages/access_points/init.py", line 34, in get_access_points
results = self.parse_output(out)
File "/Users/bengtb/.virtualenvs/temp2/lib/python3.5/site-packages/access_points/init.py", line 60, in parse_output
for network in read_plist(output):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plistlib.py", line 1006, in loads
fp, fmt=fmt, use_builtin_types=use_builtin_types, dict_type=dict_type)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plistlib.py", line 991, in load
raise InvalidFileException()
plistlib.InvalidFileException: Invalid file

OS X 10.11.6 running python 3.5.2.

list index out of range

Please provide the output of the error below this line at github.com/kootenpv/access_points/issues
list index out of range
Line:
SUPERONLINE_WiFi_57A5 -67 36 Y -- WPA(PSK/AES,TKIP/TKIP) RSN(PSK/AES,TKIP/TKIP)

[Python 2.7] access_points sometimes throws ValueError - missing rssi?

I had this running at work, but at a new location I get a ValueError if I run the script, either with access_points or access_points -n. Problematic line seems to be here.

Running OS X Yosemite with Python 2.7.11

android-daafae023c116caf:~ roger$ access_points -n
Traceback (most recent call last):
  File "/Users/roger/anaconda/bin/access_points", line 11, in <module>
    sys.exit(main())
  File "/Users/roger/anaconda/lib/python2.7/site-packages/access_points/__init__.py", line 153, in main
    access_points = wifi_scanner.get_access_points()
  File "/Users/roger/anaconda/lib/python2.7/site-packages/access_points/__init__.py", line 33, in get_access_points
    results = self.parse_output(out)
  File "/Users/roger/anaconda/lib/python2.7/site-packages/access_points/__init__.py", line 62, in parse_output
    ap = AccessPoint(ssid, bssid, rssi_to_quality(int(rssi)), security)
ValueError: invalid literal for int() with base 10: ''

APs with SSID starting with SSID crash the program

I have a AP nearby that starts with SSID and that crashes the program.

A simple (but not complete) fix is checking SSID BSSID is in the line - it's a bit more unlikely.

  File "/usr/local/lib/python3.5/site-packages/whereami/get_data.py", line 14, in sample
    aps = wifi_scanner.get_access_points()
  File "/usr/local/lib/python3.5/site-packages/access_points/__init__.py", line 33, in get_access_points
    results = self.parse_output(out)
  File "/usr/local/lib/python3.5/site-packages/access_points/__init__.py", line 55, in parse_output
    bbsid = line.index("BSSID")
ValueError: substring not found
$ /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s

                            SSID BSSID             RSSI CHANNEL HT CC SECURITY (auth/unicast/group)
                        ...
                       SSID2-2.4 a0...e8 -90  11      Y  US NONE
                        ...
2 IBSS networks found:
                            SSID BSSID             RSSI CHANNEL HT CC SECURITY (auth/unicast/group)
                            ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.