Created
March 30, 2019 09:59
-
-
Save lifeofcoding/fc07fbd91209c8315cebca9a34a54eee to your computer and use it in GitHub Desktop.
get machine external ip
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 | |
# 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