Show quality of a wifi network

Fixes #2
parent 5e27bc49
Pipeline #53566642 passed with stage
in 1 minute and 12 seconds
......@@ -4,7 +4,7 @@ from argparse import ArgumentParser
from subprocess import run, PIPE, CalledProcessError
from shutil import which
from sys import exit, stdout, argv
from typing import Optional, List, Dict
from typing import Optional, List, Dict, Any
from re import sub
import os
......@@ -15,16 +15,16 @@ def colorize(code: int, content: str) -> str:
return content
def match_property(name: str, line: str, prefix: int = 20) -> Optional[str]:
prefixStr = "{0}{1}:".format(' ' * prefix, name)
def match_property(name: str, line: str, prefix: int = 20, delim: str = ":") -> Optional[str]:
prefixStr = "{0}{1}{2}".format(' ' * prefix, name, delim)
if prefixStr in line:
return sub(r'^"(.*)"$', r"\1", line.split(prefixStr, 1)[1])
return None
def gather_wireless_info(output: List[str]) -> List[Dict[str, str]]:
networks: List[Dict[str, str]] = []
current_object: Dict[str, str] = {}
def gather_wireless_info(output: List[str]) -> List[Dict[str, Any]]:
networks: List[Dict[str, Any]] = []
current_object: Dict[str, Any] = {}
first_found: bool = False
for line in output:
if "{0}Cell".format(' ' * 10) in line:
......@@ -46,6 +46,11 @@ def gather_wireless_info(output: List[str]) -> List[Dict[str, str]]:
auth_suites = match_property("Authentication Suites (1) ", line, 24)
if auth_suites is not None:
current_object["auth"] = colorize(1, auth_suites[1:])
quality = match_property("Quality", line, 20, "=")
if quality is not None:
expression = quality.split(" ", 1)[0]
left, right = expression.split("/", 1)
current_object["quality"] = int(int(left) / int(right) * 100)
if current_object != {}:
networks.append(current_object)
......@@ -135,7 +140,8 @@ def main() -> None:
current_indicator = " "
wifi_dns = " "
print(f"{current_indicator} {colorize(1, colorize(32, 'Network'))}: {colorize(32, n['ssid'])}")
print(f"{current_indicator} {colorize(1, colorize(32, 'Network'))}: "
+ f"{colorize(32, n['ssid'])} ({colorize(1, n['quality'])}%)")
print(f" {colorize(1, 'Secured')}: {n['enc']} ({n['auth']})")
if current_indicator != " ":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment