From 1a1515f2a1f462b44e7abc59d3ec2c6075f93f3e Mon Sep 17 00:00:00 2001 From: Justin Date: Wed, 19 Jul 2023 19:20:37 +0800 Subject: [PATCH] try and except just in case --- server.py | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/server.py b/server.py index 59124d5..476ef51 100755 --- a/server.py +++ b/server.py @@ -1734,29 +1734,32 @@ def savePromptStartStop(): @app.route("/scanNetworks", methods=["PUT", "POST"]) def scanNetworks2(): - output = subprocess.check_output(['sudo', 'iwlist', 'wlan0', 'scan']) - output_str = output.decode('utf-8') - lines = output_str.split('Cell') + try: + output = subprocess.check_output(['sudo', 'iwlist', 'wlan0', 'scan']) + output_str = output.decode('utf-8') + lines = output_str.split('Cell') - global networks - networks = {} - - for line in lines: - if 'ESSID:""\n' not in line and 'Scan completed' not in line: - ssid = line.split('ESSID:')[1].split('\n')[0] - ssid = ssid.replace('"', '', 1) - ssid = ssid[::-1].replace('"', '', 1)[::-1] - if 'AES' in ssid: - ssid = ssid.replace("AES", "CCMP") - try: - group_cipher = line.split('Group Cipher : ')[1].split('\n')[0] - pair_cipher = line.split('Pairwise Ciphers (1) : ')[1].split('\n')[0] - except: - group_cipher = '' - pair_cipher = '' - # quality = line.split('Quality=')[1].split('Signal level')[0].replace(" ", "") - networks[ssid] = {'group_cipher': group_cipher, 'pair_cipher': pair_cipher} + global networks + networks = {} + for line in lines: + if 'ESSID:""\n' not in line and 'Scan completed' not in line: + ssid = line.split('ESSID:')[1].split('\n')[0] + ssid = ssid.replace('"', '', 1) + ssid = ssid[::-1].replace('"', '', 1)[::-1] + if 'AES' in ssid: + ssid = ssid.replace("AES", "CCMP") + try: + group_cipher = line.split('Group Cipher : ')[1].split('\n')[0] + pair_cipher = line.split('Pairwise Ciphers (1) : ')[1].split('\n')[0] + except: + group_cipher = '' + pair_cipher = '' + # quality = line.split('Quality=')[1].split('Signal level')[0].replace(" ", "") + networks[ssid] = {'group_cipher': group_cipher, 'pair_cipher': pair_cipher} + except: + global networks + networks = {} return (networks)