Skip to content

Instantly share code, notes, and snippets.

@zipall
Last active October 5, 2020 05:57
Show Gist options
  • Save zipall/aa82a13a6f8260d06c6f573ae09473f8 to your computer and use it in GitHub Desktop.
Save zipall/aa82a13a6f8260d06c6f573ae09473f8 to your computer and use it in GitHub Desktop.
Get external IP address
#!/bin/sh
# get external IP address
# via opendns
# used for outgoing Internet connections
# METHOD can be: dns (default), http, https, ftp, telnet
case "$1" in
""|dns) dig +short myip.opendns.com @resolver1.opendns.com ;;
http) curl -s http://whatismyip.akamai.com/ && echo ;;
https) curl -s https://4.ifcfg.me/ ;;
ftp) echo close | ftp 4.ifcfg.me | awk '{print $4; exit}' ;;
telnet) nc 4.ifcfg.me 23 | grep IPv4 | cut -d' ' -f4 ;;
*) echo Bad argument >&2 && exit 1 ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment