Friday, October 11, 2013

Easy way to find your public IP in scripts or CLI

There is a lot of online tools that gives your public IP but most of them are either not accepting cli User-Agent or they require nasty parsing with AWK,grep,sed,etc

Best way to get your public IP address is to use ifconfig.me which only returns the IP; simple and efficient.
 $ curl http://ifconfig.me  
The only problem is the responsiveness (few seconds).

Another cool way is to query the opendns servers :
 $ dig +short myip.opendns.com @resolver1.opendns.com
This method is pretty fast but requires the dig command (part of the bind-utils package).

1 comment:

  1. That indeed works but it is not very handy if you're querying it from command line :-)

    ReplyDelete