@@ -32,7 +32,7 @@ def cli_config_check() -> bool:
32
32
def get_signal () -> str :
33
33
34
34
try :
35
- ret = subprocess .check_output ([get_airport (), "-s " ], text = True , timeout = 30 )
35
+ ret = subprocess .check_output ([get_airport (), "--scan " ], text = True , timeout = 30 )
36
36
except subprocess .CalledProcessError as err :
37
37
logging .error (f"consider slowing scan cadence. { err } " )
38
38
@@ -42,30 +42,29 @@ def get_signal() -> str:
42
42
def parse_signal (raw : str ) -> list [dict [str , T .Any ]]:
43
43
44
44
isroot = running_as_root ()
45
- if not isroot :
46
- raise RuntimeError ("airport requires running as sudo to get BSSID" )
47
45
48
46
psudo = r"\s*([0-9a-zA-Z\s\-\.]+)\s+([0-9a-f]{2}(?::[0-9a-f]{2}){5})\s+(-\d{2,3})"
49
47
# BSSID only present if sudo
50
- # puser = r"\s*([0-9a-zA-Z\s\-\.]+)\s+(-\d{2,3})"
48
+ puser = r"\s*([0-9a-zA-Z\s\-\.]+)\s+(-\d{2,3})"
51
49
# non-sudo has no BSSID
52
50
53
- p = psudo
54
- i = 2
55
-
51
+ p = psudo if isroot else puser
52
+ isig = 3 if isroot else 2
53
+ ibssid = 2
56
54
pat = re .compile (p )
57
55
dat : list [dict [str , str ]] = []
58
56
59
57
for line in raw .split ("\n " ):
60
58
mat = pat .match (line )
61
59
if mat :
62
60
# Hidden SSID optout implicitly excluded by regex
63
- ssid = mat .group (1 )
61
+ ssid = mat .group (1 ). strip ()
64
62
# optout
65
63
if ssid .endswith ("_nomap" ):
66
64
continue
67
- dat .append (
68
- {"ssid" : ssid , "macAddress" : mat .group (i ), "signalStrength" : mat .group (i + 1 )}
69
- )
65
+ d = {"ssid" : ssid , "signalStrength" : mat .group (isig )}
66
+ if isroot :
67
+ d ["macAddress" ] = mat .group (ibssid )
68
+ dat .append (d )
70
69
71
70
return dat
0 commit comments