Skip to content

Commit

Permalink
Merge pull request #1 from nicob-dev/listNetworks
Browse files Browse the repository at this point in the history
List networks
  • Loading branch information
pelonchasva authored Dec 16, 2022
2 parents 26fc88f + 816759c commit b0299c6
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions wifi_password/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def get_platform() -> str:
Returns the name of the platform where the application is currently running
"""
platforms = {
'linux': constants.LINUX,
'linux1': constants.LINUX,
'linux2': constants.LINUX,
'darwin': constants.MAC,
Expand All @@ -34,9 +35,16 @@ def get_profiles() -> list:

try:
if platform == constants.MAC:
pass
# Command found here : https://coderwall.com/p/ghl-cg/list-known-wlans
profiles = run_command(f"defaults read ~/Library/Logs/com.apple.wifi.syncable-networks.plist | grep \" SSID\" | sed 's/^.*= \(.*\);$/\\1/' | sed 's/^\"\\(.*\)\"$/\\1/'").split('\n')
elif platform == constants.LINUX:
pass
if os.getuid() != 0:
ssid = run_command(f"sudo ls /etc/NetworkManager/system-connections/ | grep .nmconnection").split('\n')
else:
ssid = run_command(f"ls /etc/NetworkManager/system-connections/ | grep .nmconnection").split('\n')

for entry in ssid:
profiles.append(entry.split('.nmconnection')[0])
elif platform == constants.WINDOWS:
# Reference: https://www.geeksforgeeks.org/getting-saved-wifi-passwords-using-python/
# getting meta data
Expand Down Expand Up @@ -69,8 +77,11 @@ def generate_wifi_dict(profiles: list) -> dict:
return

for ssid in profiles:
password = get_password(ssid)

if get_platform() == constants.MAC and len(profiles) > 1:
password = "*****"
else:
password = get_password(ssid)

wifi_dict[ssid] = password

return wifi_dict
Expand Down Expand Up @@ -143,6 +154,10 @@ def print_dict(ssid: dict) -> None:
print("{:<30}| {:<}".format(key, value))

print("----------------------------------------------")
# If macOS and list

if get_platform() == constants.MAC and len(ssid) > 1:
print(f"Use 'wifi-password -s <SSID>' to find a specific WIFI password")

def generate_qr_code(ssid: str, password: str, path: str, show_qr: bool) -> None:
"""
Expand Down

0 comments on commit b0299c6

Please sign in to comment.