Skip to content

Commit

Permalink
improve wifi SSID matching (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolas-S authored Dec 6, 2023
1 parent e8a8752 commit c1a8d23
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,9 @@ def connect(self, ssid: str, password: str, timeout: float = 15) -> bool:
discovered = False
while not discovered and (time.time() - start) <= timeout:
# Scan for network
response = cmd(f"{self.sudo} nmcli device wifi list")
response = cmd(f"{self.sudo} nmcli -f SSID device wifi list")
for result in response.splitlines()[1:]: # Skip title row
# Remove * in IN-USE column since it makes the SSID column non-determinant
if result.strip(" *").split()[1] == ssid:
if result.strip() == ssid.strip():
discovered = True
break
if discovered:
Expand Down Expand Up @@ -457,10 +456,9 @@ def connect(self, ssid: str, password: str, timeout: float = 15) -> bool:
while not discovered and (time.time() - start) <= timeout:
# Scan for network
cmd(f"{self.sudo} nmcli device wifi rescan")
response = cmd(f"{self.sudo} nmcli device wifi list")
response = cmd(f"{self.sudo} nmcli -f SSID device wifi list")
for result in response.splitlines()[1:]: # Skip title row
# Remove * in IN-USE column since it makes the SSID column non-determinant
if result.strip(" *").split()[1] == ssid:
if result.strip() == ssid.strip():
discovered = True
break
if discovered:
Expand Down Expand Up @@ -693,8 +691,12 @@ def connect(self, ssid: str, password: str, timeout: float = 15) -> bool:
response = cmd(
r"/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport --scan"
)
for result in response.splitlines()[1:]: # Skip title row
if result.split()[0] == ssid:
lines = response.splitlines()
ssid_end_index = lines[0].index("SSID") + 4 # Find where the SSID column ends

for result in lines[1:]: # Skip title row
current_ssid = result[:ssid_end_index].strip()
if current_ssid == ssid.strip():
discovered = True
break
if discovered:
Expand Down

0 comments on commit c1a8d23

Please sign in to comment.