How can I get my external IP address in bash?

Using dig with OpenDNS as resolver:

dig +short myip.opendns.com @resolver1.opendns.com
Perhaps alias it in your bashrc so it’s easy to remember

alias wanip=’dig +short myip.opendns.com @resolver1.opendns.com’
Responds with a plain ip address:

$ wanip
12.100.14.123

 

 

 curl -s http://whatismijnip.nl |cut -d " " -f 5

curl -s icanhazip.com




The fastest method using DNS:

dig +short myip.opendns.com @resolver1.opendns.com

or using externalip :

externalip dns

The fastest using HTTP:

curl -s http://whatismyip.akamai.com/

or using externalip:

externalip http

The fastest using HTTPS with a valid cert:

curl -s https://4.ifcfg.me/

or using externalip:

externalip https

Using telnet:

With nc command:

nc 4.ifcfg.me 23 | grep IPv4 | cut -d' ' -f4

or using externalip:

externalip telnet

With telnet command:

telnet 4.ifcfg.me 2>&1 | grep IPv4 | cut -d' ' -f4

Using FTP:

echo close | ftp 4.ifcfg.me | awk '{print $4; exit}'

or using externalip:

externalip ftp

All of the above can be run using my externalip script as:

externalip dns
externalip http
externalip https
externalip telnet
externalip ftp


source : unix.stackexchange.com/questions/22615/how-can-i-get-my-external-ip-address-in-bash

https://github.com/rsp/scripts/blob/master/externalip.md#externalip

https://github.com/rsp/scripts/blob/master/externalip-benchmark

wget -O – -q http://whatismyip.org/

$ curl -s http://whatismyip.org | grep -o ‘\([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\}’

curl ident.me
OR

curl ifconfig.me
OR

curl tnx.nl/ip
OR

curl ipecho.net/plain
OR

curl ip.appspot.com
OR

curl whatismyip.akamai.com
OR

curl icanhazip.com
OR

curl wgetip.com
OR

curl ip.tyk.nu
OR

curl curlmyip.com
OR

curl corz.org/ip
OR

curl bot.whatismyipaddress.com

reference yourownlinux.com/2014/01/how-to-determine-your-public-ip-address-from-linux-terminal.html

netcat icanhazip.com 80 <<< $'GET / HTTP/1.1\nHost: icanhazip.com\n\n' | tail -n1 wget -q -O - checkip.dyndns.org | sed -e 's/[^[:digit:]\|.]//g' ifcfg.me supports: curl ifcfg.me nslookup . ifcfg.me telnet ifcfg.me ftp ifcfg.me finger @ifcfg.me curl http://checkip.amazonaws.com w3m -no-cookie -dump "http://www.whatismyip.com/" | grep -A 1 -m 1 "Your IP:" | tail -n 1