From aecc2138b889af0aacbfd964be4be6f0576e709d Mon Sep 17 00:00:00 2001 From: Sylvain Pineau Date: Tue, 14 Jul 2020 13:45:13 +0200 Subject: bin:wifi_time2reconnect -> wifi_time2reconnect.py --- bin/wifi_time2reconnect | 69 ---------------------------------------------- bin/wifi_time2reconnect.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 69 deletions(-) delete mode 100755 bin/wifi_time2reconnect create mode 100755 bin/wifi_time2reconnect.py (limited to 'bin') diff --git a/bin/wifi_time2reconnect b/bin/wifi_time2reconnect deleted file mode 100755 index d4ae2c0..0000000 --- a/bin/wifi_time2reconnect +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env python3 - -import os -import re -import sys -import time -import subprocess -from datetime import datetime -try: - from subprocess import DEVNULL # >= python3.3 -except ImportError: - import os - DEVNULL = open(os.devnull, 'wb') - -IFACE = None -TIMEOUT = 30 - - -def main(): - """ - Check the time needed to reconnect an active WIFI connection - """ - devices = subprocess.getoutput('nmcli dev') - match = re.search('(\w+)\s+(802-11-wireless|wifi)\s+connected', devices) - if match: - IFACE = match.group(1) - else: - print("No active wifi connection detected", file=sys.stderr) - return 1 - - try: - dev_status = subprocess.check_output( - ['nmcli', '-t', '-f', 'devices,uuid', 'con', 'status'], - stderr=DEVNULL, - universal_newlines=True) - except subprocess.CalledProcessError: - dev_status = subprocess.check_output( - ['nmcli', '-t', '-f', 'device,uuid', 'con', 'show'], - stderr=DEVNULL, - universal_newlines=True) - match = re.search(IFACE+':(.*)', dev_status) - uuid = None - if match: - uuid = match.group(1) - else: - return 1 - - subprocess.call( - 'nmcli dev disconnect iface %s' %IFACE, - stdout=open(os.devnull, 'w'), - stderr=subprocess.STDOUT, - shell=True) - - time.sleep(2) - start = datetime.now() - - subprocess.call( - 'nmcli con up uuid %s --timeout %s' %(uuid, TIMEOUT), - stdout=open(os.devnull, 'w'), - stderr=subprocess.STDOUT, - shell=True) - - delta = datetime.now() - start - print('%.2f Seconds' %delta.total_seconds()) - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/bin/wifi_time2reconnect.py b/bin/wifi_time2reconnect.py new file mode 100755 index 0000000..d4ae2c0 --- /dev/null +++ b/bin/wifi_time2reconnect.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 + +import os +import re +import sys +import time +import subprocess +from datetime import datetime +try: + from subprocess import DEVNULL # >= python3.3 +except ImportError: + import os + DEVNULL = open(os.devnull, 'wb') + +IFACE = None +TIMEOUT = 30 + + +def main(): + """ + Check the time needed to reconnect an active WIFI connection + """ + devices = subprocess.getoutput('nmcli dev') + match = re.search('(\w+)\s+(802-11-wireless|wifi)\s+connected', devices) + if match: + IFACE = match.group(1) + else: + print("No active wifi connection detected", file=sys.stderr) + return 1 + + try: + dev_status = subprocess.check_output( + ['nmcli', '-t', '-f', 'devices,uuid', 'con', 'status'], + stderr=DEVNULL, + universal_newlines=True) + except subprocess.CalledProcessError: + dev_status = subprocess.check_output( + ['nmcli', '-t', '-f', 'device,uuid', 'con', 'show'], + stderr=DEVNULL, + universal_newlines=True) + match = re.search(IFACE+':(.*)', dev_status) + uuid = None + if match: + uuid = match.group(1) + else: + return 1 + + subprocess.call( + 'nmcli dev disconnect iface %s' %IFACE, + stdout=open(os.devnull, 'w'), + stderr=subprocess.STDOUT, + shell=True) + + time.sleep(2) + start = datetime.now() + + subprocess.call( + 'nmcli con up uuid %s --timeout %s' %(uuid, TIMEOUT), + stdout=open(os.devnull, 'w'), + stderr=subprocess.STDOUT, + shell=True) + + delta = datetime.now() - start + print('%.2f Seconds' %delta.total_seconds()) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) -- cgit v1.2.3