Skip to content

Commit

Permalink
Merge pull request #26 from barak/master
Browse files Browse the repository at this point in the history
robustness and safety tweaks
  • Loading branch information
sdushantha authored Feb 1, 2021
2 parents 9259649 + 031014a commit bffdb39
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions wifi_password/wifi_password.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ def get_ssid():
if which("nmcli") is None:
print_error("Network Manager is required to run this program on Linux.")

ssid = run_command("nmcli -t -f active,ssid dev wifi | egrep '^yes' | cut -d\: -f2")
ssid = run_command("nmcli -t -f active,ssid dev wifi | egrep '^yes:' | sed 's/^yes://'")
ssid = ssid.replace("\n", "")

elif sys.platform == "win32":
ssid = run_command("netsh wlan show interfaces | findstr SSID").replace("\r", "")
if ssid == "":
print_error("SSID was not found")

ssid = re.findall(r"[^B]SSID\s+:\s(.*)", ssid)[0]

return ssid
Expand All @@ -60,9 +60,10 @@ def get_password(ssid):
elif sys.platform == "linux":
# Check if the user is running with super user privilages
if os.geteuid() != 0:
print_error(f"You need to run '{sys.argv[0]}' as root")
password = run_command(f"sudo nmcli -s -g 802-11-wireless-security.psk connection show '{ssid}'")
else:
password = run_command(f"nmcli -s -g 802-11-wireless-security.psk connection show '{ssid}'")

password = run_command(f"nmcli -s -g 802-11-wireless-security.psk connection show '{ssid}'")
password = password.replace("\n", "")

elif sys.platform == "win32":
Expand Down

0 comments on commit bffdb39

Please sign in to comment.