Quickly obtain your public IP

Whenever I’m at a customer for work, I sometimes need to know the public ip. I always went with a browser to checkip.dyndns.org to get the current public ip of the customer. lauching the browser, typing in the website url.. takes time. I always have my terminal window open, so I tought, can’t we script this? Yes we can:

publicip_=`curl -s --connect-timeout 3 checkip.dyndns.org | sed 's/[^0-9\.]//g'`
echo $publicip_

save it as publicip under /usr/local/sbin/ and execute chmod +x /usr/local/sbin/publicip . whenever you need the public ip, just run “publicip” from the terminal and it shouts out your current public ip.

you’re welcome.


subutux wrote 34 posts

Post navigation

Leave a Reply