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:

#!/bin/bash
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.

Tags: , , , ,

Leave a Reply

Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).