Skip to content

Instantly share code, notes, and snippets.

@lifeofcoding
Created March 30, 2019 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lifeofcoding/fc07fbd91209c8315cebca9a34a54eee to your computer and use it in GitHub Desktop.
Save lifeofcoding/fc07fbd91209c8315cebca9a34a54eee to your computer and use it in GitHub Desktop.
get machine external ip
#!/bin/sh
# get external IP address
# used for outgoing Internet connections
# see: https://github.com/rsp/scripts/blob/master/externalip.md
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