How to Get Public IP Address in Linux

Problem with WGET/CURL

You might have a seen a lot of wget/curl related way to get an IP address. One of my clients was using it and it looks like somehow he was blocked. Now it might have not been the case if he was spoofing but assume that he would get blocked eventually, I used dig with opendns (over Google).

Blocking isn’t one way – may be the service is down – it happened to us all isn’t it?

With dig, system is running for a year and my Client hired me for another project and asked me how I did it. So I thought I should share it to readers as well.

Most Reliable way is through dig

dig +short
dig TXT +short | awk -F'"' '{ print $2}'

A little less reliable way is through host

host | grep " has" | awk '{print $4}'

Worth Sharing?


Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>