What is my Public IP Address?

August 22nd, 2007 mysurface Posted in curl, egrep, grep, Misc, Text Manipulation, wget | Hits: 115995 | 15 Comments »

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 :)

[中文翻译]

15 Responses to “What is my Public IP Address?”

  1. 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. ;)

  2. 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

  3. this is a great piece of work. Good job man and a great website

  4. [...] 我的公网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/ [...]

  5. this is a great piece of work. Good job man and a great website

  6. View your ip address and more:
    http://my-i-p.com

  7. Keep up the good work dude!

  8. oo yeah…this is the best article…tnx :X

  9. oo yeah…this is the best article…tnx :X

  10. I all the time emailed this blog post page to
    all my associates, for the reason that if like to read it after that my contacts will too.

    Also visit my web blog; Janet Leigh Nude

  11. Nasze kasy fiskalne warszawa s? najbardziej niezawodne w ca?ej polsce zapraszamy do naszej strony www

  12. Excellent blog here! Also your site loads up fast! What web host are you using?
    Can I get your affiliate link to your host? I wish my site loaded up as fast as yours lol

  13. Hmm it appears like your site ate my first comment (it was extremely long) so I guess I’ll just sum it
    up what I had written and say, I’m thoroughly enjoying your
    blog. I as well am an aspiring blog writer but
    I’m still new to the whole thing. Do you have any helpful hints for rookie blog writers?

    I’d definitely appreciate it.

    My weblog: phone conferencing

  14. Thanks for finally talking about > What is my Public IP Address?
    ? Linux by Examples < Loved it!

Leave a Reply