Created
September 12, 2017 15:54
-
-
Save adamheins/d7e4cb9f6c31c2d090052c4ff3c91a96 to your computer and use it in GitHub Desktop.
Script to print wifi network info when using NetworkManager on Ubuntu.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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