Skip to content

Instantly share code, notes, and snippets.

@adamheins
Created September 12, 2017 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamheins/d7e4cb9f6c31c2d090052c4ff3c91a96 to your computer and use it in GitHub Desktop.
Save adamheins/d7e4cb9f6c31c2d090052c4ff3c91a96 to your computer and use it in GitHub Desktop.
Script to print wifi network info when using NetworkManager on Ubuntu.
#!/bin/bash
# Get the name of the current network if one is not provided.
if [ -z "$1" ]; then
network_name=$(iwconfig 2>&1 | grep "SSID" | cut -d '"' -f2)
else
network_name=$1
fi
# Probably very system-dependent on Ubuntu and on using NetworkManager.
network_file="/etc/NetworkManager/system-connections/$network_name"
# Check for permissions.
if [ ! -r "$network_file" ]; then
echo "Permission denied. Try 'sudo'."
exit 1
fi
# Parse the network password from the file.
network_pass=$(grep "k=" < "$network_file" | sed "s/.*=//g")
printf "SSID: %s\n" "$network_name"
printf "Pass: %s\n" "$network_pass"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment