Skip to content

Instantly share code, notes, and snippets.

@DennisLfromGA
Created August 25, 2015 18:29
Show Gist options
  • Save DennisLfromGA/ab40940d37be84ae3a88 to your computer and use it in GitHub Desktop.
Save DennisLfromGA/ab40940d37be84ae3a88 to your computer and use it in GitHub Desktop.
Script to grab your WAN IP address using various means.
#!/usr/bin/env sh
ipurl="icanhazip.com"
if hash dig 2>/dev/null; then cmd="dig +short myip.opendns.com @resolver1.opendns.com"; ipurl=""
elif hash curl 2>/dev/null; then cmd="curl"
elif hash wget 2>/dev/null; then cmd="wget -qO-"
else echo "*** No app (dig,curl,wget) found - exiting ***"; exit 2; fi
[ -n "$1" ] && echo -n "$cmd $ipurl - "
eval $cmd $ipurl || ret=$?
exit $ret
@DennisLfromGA
Copy link
Author

Whew!

Anyone is welcome to use my public stuff so please go ahead if you like.

I most likely grabbed this from someone else's unlicensed script but that's what's great about Linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment