-
-
Save juanfal/8f72e30182b383df873669bb5349fee2 to your computer and use it in GitHub Desktop.
local and external IP bash resolver
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/sh | |
# myip | |
# juanfc 2024-01-11 | |
# wget http://ipinfo.io/ip -qO - | |
# ipconfig getifaddr en0 2>/dev/null || ipconfig getifaddr en1 2>/dev/null | |
# dig +short myip.opendns.com @208.67.222.222 | |
# dig +short myip.opendns.com @resolver1.opendns.com | |
# ipconfig getifaddr en0 2>/dev/null || ipconfig getifaddr en1 2>/dev/null | |
# https://stackoverflow.com/questions/33743824/how-to-print-my-public-ip-address-in-the-terminal-using-wget | |
if [[ $# > 0 ]]; then | |
if [[ $@ = "-h" ]]; then | |
printf "$0 [-h|anything]\n" | |
printf "\twithout arguments print external IP\n" | |
printf "\twith any argument different than -h, the local IP\n" | |
printf "\twith -h, this help\n" | |
else | |
ipconfig getifaddr en0 2>/dev/null || ipconfig getifaddr en1 2>/dev/null | |
fi | |
else | |
curl https://ipecho.io/plain | |
echo | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment