From 45d799708608ef5a30a6feb0078e1109dc0d4613 Mon Sep 17 00:00:00 2001 From: Kyle Krattiger Date: Thu, 22 Apr 2021 18:34:04 -0700 Subject: [PATCH 1/9] Fixed typos in README.md. Fixed bug that was preventing module from running in python3. --- README.md | 2 +- iw_parse.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4f33936..76f088b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Parse the output of iwlist scan to get the name, address, quality, channel, and Dependencies ------------ -* [pip](http://www.pip-installer.org/en/latest/installing.html "pip installation guide") - If you don't have pip installed, followed the link. +* [pip](http://www.pip-installer.org/en/latest/installing.html "pip installation guide") - If you don't have pip installed, follow this link. Installation diff --git a/iw_parse.py b/iw_parse.py index 9be9007..ba6b791 100644 --- a/iw_parse.py +++ b/iw_parse.py @@ -1,6 +1,6 @@ #! /usr/bin/env python -# Hugo Chargois - 17 jan. 2010 - v.0.1 +# Hugo Chargois - 22 Apr. 2021 - v0.0.4 # Parses the output of iwlist scan into a table # You can add or change the functions to parse the properties @@ -319,7 +319,7 @@ def call_iwlist(interface='wlan0'): @return string properties: iwlist output """ - return subprocess.check_output(['iwlist', interface, 'scanning']) + return subprocess.check_output(['iwlist', interface, 'scanning'],text=True) def get_interfaces(interface="wlan0"): """ Get parsed iwlist output @@ -334,4 +334,3 @@ def get_interfaces(interface="wlan0"): properties: dictionary of iwlist attributes """ return get_parsed_cells(call_iwlist(interface).split('\n')) - From 894b9ecddfa476a53d16811da831fe58ee0710f0 Mon Sep 17 00:00:00 2001 From: Kyle Krattiger Date: Mon, 26 Apr 2021 15:43:19 -0700 Subject: [PATCH 2/9] Added try statement to allow catch of TypeError --- iw_parse.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/iw_parse.py b/iw_parse.py index ba6b791..09e2534 100644 --- a/iw_parse.py +++ b/iw_parse.py @@ -319,7 +319,7 @@ def call_iwlist(interface='wlan0'): @return string properties: iwlist output """ - return subprocess.check_output(['iwlist', interface, 'scanning'],text=True) + return subprocess.check_output(['iwlist', interface, 'scanning']) def get_interfaces(interface="wlan0"): """ Get parsed iwlist output @@ -333,4 +333,7 @@ def get_interfaces(interface="wlan0"): @return dict properties: dictionary of iwlist attributes """ - return get_parsed_cells(call_iwlist(interface).split('\n')) + try: + return get_parsed_cells(call_iwlist(interface).split('\n')) + except TypeError: + return get_parsed_cells(call_iwlist(interface).decode('utf-8').split('\n')) From f32fb48f3496a2a866de3c969d2d4aa65688cff6 Mon Sep 17 00:00:00 2001 From: Kyle Krattiger Date: Mon, 26 Apr 2021 16:39:19 -0700 Subject: [PATCH 3/9] Added setup.py, setup.cfg, and pyproject.toml so pip build it correctly. Moved code into iw_parse/ --- iw_parse => iw_parse/iw_parse | 0 iw_parse.py => iw_parse/iw_parse.py | 2 +- pyproject.toml | 6 ++++ setup.cfg | 2 ++ setup.py | 43 +++++++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 1 deletion(-) rename iw_parse => iw_parse/iw_parse (100%) mode change 100755 => 100644 rename iw_parse.py => iw_parse/iw_parse.py (99%) create mode 100644 pyproject.toml create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/iw_parse b/iw_parse/iw_parse old mode 100755 new mode 100644 similarity index 100% rename from iw_parse rename to iw_parse/iw_parse diff --git a/iw_parse.py b/iw_parse/iw_parse.py similarity index 99% rename from iw_parse.py rename to iw_parse/iw_parse.py index 09e2534..9303ae4 100644 --- a/iw_parse.py +++ b/iw_parse/iw_parse.py @@ -1,6 +1,6 @@ #! /usr/bin/env python -# Hugo Chargois - 22 Apr. 2021 - v0.0.4 +# Hugo Chargois - 26 Apr. 2021 - v0.0.4 # Parses the output of iwlist scan into a table # You can add or change the functions to parse the properties diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..8d91941 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools", + "wheel" +] +build-backend = "setuptools.build_meta" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..8f917f5 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[metadata] +license_files = LICENSE.txt \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..eeca314 --- /dev/null +++ b/setup.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python + +# Hugo Chargois - 26 Apr. 2021 - v0.0.4 +# setup.py written by Kyle Krattiger (gitlab.com/mrmusic25) + +# Script to allow installation with pip + +import setuptools + +with open("README.md", "r") as fh: + long_description = fh.read() + +setuptools.setup( + name='iw_parse', + version='0.0.4', + description='iwlist scan for Python', + long_description=long_description, + long_description_content_type="text/markdown", + url='https://github.com/cuzzo/iw_parse', + author='Hugo Chargois', + license='BSD-2-Clause', + packages=['iw_parse'], + classifiers=[ + 'Topic :: System :: Operating System Kernels :: Linux', + 'Topic :: System :: Monitoring', + 'Topic :: System :: Networking', + 'Environment :: Console', + 'License :: OSI Approved :: BSD License', + 'Development Status :: 5 - Production/Stable', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.6', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.2', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8' + ] +) \ No newline at end of file From 0a92bbd2a03da46e92b03ad57596255c14cce7f4 Mon Sep 17 00:00:00 2001 From: Kyle Krattiger Date: Mon, 26 Apr 2021 16:52:37 -0700 Subject: [PATCH 4/9] Added scripts to params[] so iw_parse is added to PATH --- README.md | 3 ++- setup.py | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 76f088b..4a0bebe 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,13 @@ Dependencies * [pip](http://www.pip-installer.org/en/latest/installing.html "pip installation guide") - If you don't have pip installed, follow this link. +* wireless-tools - provides the Linux utility `iwlist`. Installation ------------ ```bash -pip install iw_parse +sudo -H pip install --upgrade iw_parse ``` Usage diff --git a/setup.py b/setup.py index eeca314..0cbf2f9 100644 --- a/setup.py +++ b/setup.py @@ -10,6 +10,10 @@ with open("README.md", "r") as fh: long_description = fh.read() +params = { + "scripts" : ['iw_parse/iw_parse'] +} + setuptools.setup( name='iw_parse', version='0.0.4', @@ -39,5 +43,6 @@ 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8' - ] + ], + **params ) \ No newline at end of file From 5eaca90a3552ed0910509ef70063ad79fbed1373 Mon Sep 17 00:00:00 2001 From: Kyle Krattiger Date: Mon, 26 Apr 2021 17:10:01 -0700 Subject: [PATCH 5/9] Updated README.md --- README.md | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4a0bebe..c9458bc 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,18 @@ iw_parse Parse the output of iwlist scan to get the name, address, quality, channel, and encryption type of all networks broadcasting within your Wireless NIC's reach. +Verified working in both Python 2 and Python 3. + Dependencies ------------ -* [pip](http://www.pip-installer.org/en/latest/installing.html "pip installation guide") - If you don't have pip installed, follow this link. +* [pip](https://pip.pypa.io/en/latest/installing/ "pip installation guide") - If you don't have pip installed, follow this link. + +* [wireless-tools](https://packages.ubuntu.com/focal/wireless-tools) - provides the Linux utility `iwlist`. If not installed, you can run the following on Ubuntu/Raspberry Pi OS/Debian-based systems: -* wireless-tools - provides the Linux utility `iwlist`. +```bash +sudo apt install wireless-tools +``` Installation ------------ @@ -46,7 +52,32 @@ wireless7 A0:21:B7:5F:84:B0 44 % 11 WEP wireless8 04:A1:51:18:E8:E0 41 % 6 WPA v.1 ``` -Example from Python shell: +Example from Python 3 shell: + +```python +>>> import iw_parse +>>> from pprint import pprint +>>> networks = iw_parse.get_interfaces(interface='wlan0') +>>> pprint(networks) +[{'Address': 'F8:1E:DF:F9:B0:0B', + 'Channel': '3', + 'Encryption': 'WEP', + 'Name': 'Francis', + 'Bit Rates': '144 Mb/s', + 'Signal Level': '42', + 'Name': 'Francis', + 'Quality': '100'}, + {'Address': '86:1B:5E:33:17:D4', + 'Channel': '6', + 'Encryption': 'Open', + 'Bit Rates': '54 Mb/s', + 'Signal Level': '72', + 'Name': 'optimumwifi', + 'Quality': '100'}, + ... +``` + +Example from (legacy) Python 2 shell: ```python >>> import iw_parse @@ -74,6 +105,7 @@ Acknowledgements ---------------- * The vast majority of iw_parse was written by Hugo Chargois. +* pip installation scripts and Python 3 compatiblity written by [Kyle Krattiger](https://gitlab.com/mrmusic25) License ------- From caf4387a6715ad94c3c2981f57da5c3a6ed84822 Mon Sep 17 00:00:00 2001 From: Kyle Krattiger Date: Mon, 26 Apr 2021 17:16:16 -0700 Subject: [PATCH 6/9] Added download instructions to README.md --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index c9458bc..609cf7b 100644 --- a/README.md +++ b/README.md @@ -19,10 +19,20 @@ sudo apt install wireless-tools Installation ------------ +Recommended - using pip: + ```bash sudo -H pip install --upgrade iw_parse ``` +Alternative - manually with git: +```bash +git clone https://github.com/cuzzo/iw_parse.git +cd iw_parse +sudo -H pip install --upgrade build setuptools +sudo -H pip install . +``` + Usage ----- From 6ea058c929641ac8347e63838a85ab187592150e Mon Sep 17 00:00:00 2001 From: Kyle Krattiger Date: Mon, 26 Apr 2021 17:20:04 -0700 Subject: [PATCH 7/9] One more change to README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 609cf7b..731faa1 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ Installation Recommended - using pip: +Note: If using Python 3, try replacing `pip` with `pip3` if errors occur. + ```bash sudo -H pip install --upgrade iw_parse ``` From 242b157652b1f9723e32308499159f9c5dcf144c Mon Sep 17 00:00:00 2001 From: Kyle Krattiger Date: Thu, 29 Apr 2021 13:15:51 -0700 Subject: [PATCH 8/9] Fixed README and iw_parse binary to reflect correct import method --- README.md | 4 ++-- iw_parse/iw_parse | 4 ++-- setup.cfg | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 731faa1..0abaf42 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ wireless8 04:A1:51:18:E8:E0 41 % 6 WPA v.1 Example from Python 3 shell: ```python ->>> import iw_parse +>>> from iw_parse import iw_parse >>> from pprint import pprint >>> networks = iw_parse.get_interfaces(interface='wlan0') >>> pprint(networks) @@ -92,7 +92,7 @@ Example from Python 3 shell: Example from (legacy) Python 2 shell: ```python ->>> import iw_parse +>>> from iw_parse import iw_parse >>> networks = iw_parse.get_interfaces(interface='wlan0') >>> print networks [{'Address': 'F8:1E:DF:F9:B0:0B', diff --git a/iw_parse/iw_parse b/iw_parse/iw_parse index 022997e..394f131 100644 --- a/iw_parse/iw_parse +++ b/iw_parse/iw_parse @@ -1,8 +1,8 @@ -#! /usr/bin/env python +#!/usr/bin/env python import sys -from iw_parse import get_parsed_cells, print_cells +from iw_parse.iw_parse import get_parsed_cells, print_cells def main(): """ Pretty prints the output of iwlist scan into a table. """ diff --git a/setup.cfg b/setup.cfg index 8f917f5..af49403 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,2 @@ [metadata] -license_files = LICENSE.txt \ No newline at end of file +license_files = license.txt \ No newline at end of file From a82e9546f8e2679a552afe0a04130432c3fcd4ff Mon Sep 17 00:00:00 2001 From: Kyle Krattiger Date: Thu, 17 Mar 2022 15:45:56 -0700 Subject: [PATCH 9/9] Bumped to v0.0.5. Updated code to work in python 3.9.x<=, which consequently means removing all python2 support. Upadated README and install script to reflect these changes. Added minimum python version of 3.7.x because of subprocess. --- README.md | 18 +++++++++++------- iw_parse/iw_parse | 2 +- iw_parse/iw_parse.py | 8 +++++--- setup.py | 18 ++++++------------ 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 0abaf42..1d7f373 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,18 @@ iw_parse Parse the output of iwlist scan to get the name, address, quality, channel, and encryption type of all networks broadcasting within your Wireless NIC's reach. -Verified working in both Python 2 and Python 3. +Verified working in Python 3.7 and higher. If you need python2 support, go back to the v0.0.4 release. Dependencies ------------ -* [pip](https://pip.pypa.io/en/latest/installing/ "pip installation guide") - If you don't have pip installed, follow this link. +* [python3](https://www.python.org) - Version 3.7.x or higher + +* [pip](https://pip.pypa.io/en/latest/installing/ "pip installation guide") - If you don't have pip installed, follow this link. You should be able to install is this way as well: + +```bash +sudo apt install python3-pip +``` * [wireless-tools](https://packages.ubuntu.com/focal/wireless-tools) - provides the Linux utility `iwlist`. If not installed, you can run the following on Ubuntu/Raspberry Pi OS/Debian-based systems: @@ -21,18 +27,16 @@ Installation Recommended - using pip: -Note: If using Python 3, try replacing `pip` with `pip3` if errors occur. - ```bash -sudo -H pip install --upgrade iw_parse +sudo -H python3 -m pip install --upgrade iw_parse ``` Alternative - manually with git: ```bash git clone https://github.com/cuzzo/iw_parse.git cd iw_parse -sudo -H pip install --upgrade build setuptools -sudo -H pip install . +sudo -H python3 -m pip install --upgrade build setuptools +sudo -H python3 -m pip install . ``` Usage diff --git a/iw_parse/iw_parse b/iw_parse/iw_parse index 394f131..30dcb2c 100644 --- a/iw_parse/iw_parse +++ b/iw_parse/iw_parse @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import sys diff --git a/iw_parse/iw_parse.py b/iw_parse/iw_parse.py index 9303ae4..0c15593 100644 --- a/iw_parse/iw_parse.py +++ b/iw_parse/iw_parse.py @@ -1,6 +1,6 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 -# Hugo Chargois - 26 Apr. 2021 - v0.0.4 +# Hugo Chargois - 17 Mar. 2022 - v0.0.5 # Parses the output of iwlist scan into a table # You can add or change the functions to parse the properties @@ -319,7 +319,9 @@ def call_iwlist(interface='wlan0'): @return string properties: iwlist output """ - return subprocess.check_output(['iwlist', interface, 'scanning']) + s = subprocess.run("iwlist " + str(interface) + " scanning",shell=True,capture_output=True) + #return subprocess.check_output(['iwlist', interface, 'scanning']) + return s.stdout.decode('utf-8') # Note: This method means python3.7.x< is required now def get_interfaces(interface="wlan0"): """ Get parsed iwlist output diff --git a/setup.py b/setup.py index 0cbf2f9..2ede694 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 -# Hugo Chargois - 26 Apr. 2021 - v0.0.4 +# Hugo Chargois - 17 Mar. 2022 - v0.0.5 # setup.py written by Kyle Krattiger (gitlab.com/mrmusic25) # Script to allow installation with pip @@ -16,7 +16,7 @@ setuptools.setup( name='iw_parse', - version='0.0.4', + version='0.0.5', description='iwlist scan for Python', long_description=long_description, long_description_content_type="text/markdown", @@ -32,17 +32,11 @@ 'License :: OSI Approved :: BSD License', 'Development Status :: 5 - Production/Stable', 'Programming Language :: Python', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.6', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.2', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8' + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', ], **params ) \ No newline at end of file