summaryrefslogtreecommitdiff
diff options
-rwxr-xr-xbin/wifi_time2reconnect18
1 files changed, 16 insertions, 2 deletions
diff --git a/bin/wifi_time2reconnect b/bin/wifi_time2reconnect
index bfaa2ce..d4ae2c0 100755
--- a/bin/wifi_time2reconnect
+++ b/bin/wifi_time2reconnect
@@ -6,6 +6,11 @@ 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
@@ -16,14 +21,23 @@ 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\s+connected', devices)
+ 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
- dev_status = subprocess.getoutput('nmcli -t -f devices,uuid con status')
+ 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: