What is my Public IP Address?
August 22nd, 2007 mysurface Posted in Misc, Text Manipulation, curl, egrep, grep, wget | Hits: 34471 |
What is my public IP address? There is a lots of website can provide you the information. What if I wanna grep it for my script? We can use curl and grep for this purpose.
First, lets pick few websites that provide the service to reveal my public IP.
http://www.ipchicken.com/ - the chicken looks so funny.
http://whatismyip.com/ - a guy playing VR game.
http://myip.dk/ - a simple website but served the purpose.
Next, lets crawl the page and grep the IP
curl -s http://myip.dk/ | egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
You can use wget if you do not install curl
wget -qO - http://myip.dk/ | egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
The important part is the regex. [0-9] indicate any digit within 0 - 9 and {1,3} indicate it should appear minimum 1 time, maximum 3 times. -o indicate grep to print the matched part and -m1 is to limit the grep process to stop at first match.
http://whatismyip.org/ - no need to grep, just curl it.
curl -s http://whatismyip.org/
It seems that getting public IP from http://whatismyip.org/ is far more convenient, the limitation is that you are allow to access the page only 3 times within 10 minutes.
After all, I just enjoy greping with regex :)
Live Chat!









August 24th, 2007 at 9:38 pm
Cool!
This one is for the ‘visually impaired’ users:
mpg123 “http://moanmyip.com/output/$(curl http://www.moanmyip.com | egrep -m1 -o ‘[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}’).mp3″
Cheers. ;)
September 16th, 2007 at 4:37 pm
myip.dk and ip-adress are the old ones dunno how i even remember that ;S
check http://www.iplobster.com - cunning lobster hehe but i needed ipv4 info
October 30th, 2007 at 6:07 am
this is a great piece of work. Good job man and a great website
November 27th, 2007 at 12:01 am
[...] 我的公网IP是多少? curl -s http://myip.dk/ | egrep -m1 -o ‘[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}’ wget -qO - http://myip.dk/ | egrep -m1 -o ‘[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}’ curl -s http://whatismyip.org/ [...]
December 30th, 2007 at 5:39 pm
this is a great piece of work. Good job man and a great website
February 15th, 2008 at 6:37 am
View your ip address and more:
http://my-i-p.com