.
This commit is contained in:
@@ -7,7 +7,7 @@ from flask_login import current_user, login_required, login_user, logout_user
|
||||
from app import app
|
||||
from app.forms import LoginForm, WPAForm
|
||||
from app.models import Network, Networks, User
|
||||
from config import debug
|
||||
from config import debug, RPI
|
||||
|
||||
CMD_SCAN = "sudo nmcli -t -f SSID,SIGNAL,IN-USE,SECURITY -e yes -m tab device wifi list ifname wlxf81a6719febb --rescan yes"
|
||||
CMD_JOIN = "sudo nmcli device wifi connect *SSID* ifname wlxf81a6719febb"
|
||||
@@ -19,12 +19,40 @@ CMD_DISCONNECT = "sudo nmcli device disconnect wlxf81a6719febb"
|
||||
|
||||
def scan_networks():
|
||||
scan = []
|
||||
output = subprocess.run(CMD_SCAN.split(" "), stdout=subprocess.PIPE).stdout.decode("utf-8")
|
||||
for line in output.splitlines():
|
||||
t = line.split(":")
|
||||
if t[0] != "":
|
||||
scan.append(line)
|
||||
|
||||
if not RPI:
|
||||
output = subprocess.run(CMD_SCAN.split(" "), stdout=subprocess.PIPE).stdout.decode("utf-8")
|
||||
for line in output.splitlines():
|
||||
t = line.split(":")
|
||||
if t[0] != "":
|
||||
scan.append(line)
|
||||
else:
|
||||
output = subprocess.run(["sudo", "iwgetid"], stdout=subprocess.PIPE).stdout.decode("utf-8")
|
||||
current = output.partition("ESSID:")[2].strip().strip('"')
|
||||
|
||||
output = subprocess.run(["sudo", "iwlist", "wlan0", "scan"], stdout=subprocess.PIPE).stdout.decode("utf-8")
|
||||
a = 0
|
||||
scan = []
|
||||
for line in output.splitlines():
|
||||
connected = " "
|
||||
if a == 0:
|
||||
if line.partition("ESSID:")[2].strip('"') != "":
|
||||
a = 1
|
||||
ssid = line.partition("ESSID:")[2].strip('"')
|
||||
if ssid == current:
|
||||
connected = "*"
|
||||
if a == 1:
|
||||
if line.find("Encryption key:off") != -1:
|
||||
password = " "
|
||||
a = 2
|
||||
else:
|
||||
password = "WPA2"
|
||||
a = 2
|
||||
if a == 2:
|
||||
if line.partition("Signal level=")[2].split("/")[0] != "":
|
||||
signal = line.partition("Signal level=")[2].split("/")[0]
|
||||
a = 0
|
||||
scan.append(ssid + ":" + signal + ":" + connected + ":" + password)
|
||||
return scan
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user