Last active
October 5, 2020 05:57
-
-
Save zipall/aa82a13a6f8260d06c6f573ae09473f8 to your computer and use it in GitHub Desktop.
Get external IP address
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 | |
# 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