[wifi] update
This commit is contained in:
parent
9454163063
commit
9949c7f58c
|
@ -49,7 +49,7 @@ def edit_line_in_file(file_path, search_string, replacement_string):
|
|||
else:
|
||||
file.write(line)
|
||||
|
||||
print("The line has been edited.")
|
||||
print(f"{datetime.datetime.now()}: The line has been edited.")
|
||||
except FileNotFoundError:
|
||||
print(f"The file {file_path} does not exist.")
|
||||
except IOError as e:
|
||||
|
@ -66,6 +66,7 @@ def save_local_ip():
|
|||
# save local_ip to file
|
||||
with open('local_ip.txt', 'w') as f:
|
||||
f.write(local_ip)
|
||||
print(f"{datetime.datetime.now()}: Local IP address: {local_ip}")
|
||||
return local_ip
|
||||
except Exception as e:
|
||||
print(f"Error getting private IP: {e}")
|
||||
|
@ -116,7 +117,7 @@ def close_hotspot():
|
|||
def check_wifi_connection():
|
||||
cmd = "nmcli dev status"
|
||||
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
|
||||
time.sleep(1)
|
||||
time.sleep(2)
|
||||
output = result.stdout.strip()
|
||||
lines = output.split("\n")[1:] # Skip the header line
|
||||
for line in lines:
|
||||
|
@ -150,7 +151,7 @@ def check_wifi_connection():
|
|||
network_error_light()
|
||||
subprocess.Popen('sudo systemctl restart NetworkManager', shell=True)
|
||||
# subprocess.run(['sudo', 'systemctl', 'restart', 'NetworkManager'], check=True)
|
||||
time.sleep(5)
|
||||
time.sleep(2)
|
||||
return False, None
|
||||
|
||||
def scan_wifi():
|
||||
|
@ -161,6 +162,7 @@ def scan_wifi():
|
|||
except subprocess.CalledProcessError as e:
|
||||
print(f"{datetime.datetime.now()}: Error scanning Wi-Fi: {e}")
|
||||
network_error_light()
|
||||
print(f"{datetime.datetime.now()}: Wi-Fi scan complete...")
|
||||
ssid_list = []
|
||||
wifi_list = []
|
||||
output = result.stdout.strip()
|
||||
|
@ -207,6 +209,8 @@ def scan_wifi():
|
|||
# print("强度:", strength)
|
||||
|
||||
wifi_list.append({'ssid': ssid, 'signal': strength, 'mac': mac_address})
|
||||
with open('scaned_wifi_list.json', 'w') as f:
|
||||
json.dump(wifi_list, f)
|
||||
if len(wifi_list) == 15:
|
||||
break
|
||||
|
||||
|
@ -304,7 +308,7 @@ def submit():
|
|||
wifi_list = scan_wifi()
|
||||
start_hotspot()
|
||||
else:
|
||||
save_wifi(wifi_ssid, password) # 保存连接成功的Wi-Fi信息
|
||||
save_wifi(ssid, password) # 保存连接成功的Wi-Fi信息
|
||||
|
||||
return redirect(url_for('index'))
|
||||
|
||||
|
|
Loading…
Reference in New Issue