Last active
October 18, 2023 13:58
-
-
Save jkereako/22ce918d641f6134f0b687ec1ac29b54 to your computer and use it in GitHub Desktop.
Prints the current SSID name and the local and public IP addresses
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
#!/usr/bin/env bash | |
# | |
# ip | |
# | |
# Shows the local and public IP addresses | |
set -Eeuo pipefail | |
# Print out error messages to STDERR. | |
function err() { | |
echo -e "\033[0;31mERROR: $@\033[0m" >&2; | |
} | |
function check_connection() { | |
if ! nc -z www.google.com 80 -G1 1> /dev/null 2>&1; then | |
err "No internet connection"; exit 2; | |
fi; | |
} | |
#-- Main | |
function main() { | |
check_connection | |
ssid=$(networksetup -getairportnetwork en0) | |
local=$(ipconfig getifaddr en0) | |
public=$(dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com) | |
echo "${ssid}" | |
echo "----------------------" | |
# The IP addresses are wrapped in quotes. This removes them. | |
echo "Local: ${local//\"/}" | |
echo "Public: ${public//\"/}" | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment