A Bash Command To Get Your IP

This is a one line bash command to get your IP.

It queries whatismyip.com, processes the output and displays the IP.

You might want to add it to your aliases file.

UPDATE: Don’t use this command, use the one in the end of this post

1
wget -O - whatismyip.com 2> /dev/null | grep "Your IP Address Is" | sed -e 's/^.*Is//' -e 's/<.*$//'

Enjoy ;)

Update: A nice guy – Theodore- has put this along with a script of his own to get a simple and neat bash script which shows both the internal (wired and wifi) and the external IPs. Script posted at his blog. Script in Theodore’s post is for Mac, but can be easily modified to run on Linux. Thanks Theodore.

Update2: Thanks to commenter Paul Dorman, I visited whatismyip’s forum and realized that they don’t allow to visit their home page too many times (they might ban you if you do so). However, they give an alternative: Another page in their website where you can get your IP. So the new command to query your IP is:

1
wget http://www.whatismyip.com/automation/n09230945.asp -O - 2> /dev/null; echo

Please use this and not the previously mentioned command.
Thanks Paul.

If you enjoyed this post, make sure you subscribe to my RSS feed!

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

No related posts.

Tags: ,

Monday, March 9th, 2009 Bash

10 Comments to A Bash Command To Get Your IP

  • De-Escalate says:

    I tweeted this, but for those who are not on Twitter, what about using ifconfig | grep inet? You can use sed and grep to get output that only includes the IP, or just to format things more nicely. I made a bash script that does only that, for convenience when I was having trouble with my school’s wireless. I’d be happy to send it to you if you would like to take a look at it.

  • Amir Watad says:

    Hi De-Escalate,
    Thanks for your comment.
    I agree that ifconfig will show you the IP, but it’s not always the same IP that the external world see.
    If you’re behind a NAT for example, you computer will “think” that it has a certain IP (which was assigned to it by the NAT and identifies it inside the LAN), but if you visit a website, it will see a different IP, which is in the above case the IP assigned by your ISP to the NAT.
    ifconfig will give you the internal IP, whatismyip is an external site, so it will see you “real” IP.
    And yes, please send the script to me. My Email appears in the top of the sidebar.
    Thanks again :)

  • De-Escalate says:

    That makes sense… we were trying to solve different problems. I might tack your command to my script so that I can have inside and outside IPs. Thanks!

  • Paul Dorman says:

    I got banned for trying this several times within 5 minutes. However the site actually has a place for scraping: http://www.whatismyip.com/automation/n09230945.asp

    They tell you about it when they ban you :o )

  • Amir Watad says:

    Hi Paul,
    Thank you for your comment. I checked in their forums and you’re right.
    I updated the post.
    Thanks for sharing this information. :)

  • Binny V A says:

    This is my method

    curl -s checkip.dyndns.org|sed -e ‘s/.*Current IP Address: //’ -e ‘s/<.*$//’

  • vando says:

    I’ve a more simple method:

    curl icanhazip.com

    bye!

  • Trackbacks/Pingbacks

  • [...] to Twitter, I just happened to run across a post about getting the external IP in bash on Amir Watad’s blog. So simple. I like [...]

  • Technology news for 2009-03-09 | Technology News says:

    [...] Posted an item embee: A Bash Command To Get Your IP (via Digg) [...]

  • Leave a Reply

    my email
    my photo
    Hi,
    My name is Amir Watad. I have a BSc. in biomedical engineering from The Biomedical Engineering school , Technion , Israel, and a BSc. in electrical engineering from The Electrical Engineering school , Technion , Israel.
    I'm a Verification Engineer in Mellanox Technologies Ltd.
    I love Linux, the Command Line and the OpenSource Community.
    I used to write Poems (Arabic) when I was able to find time for this.
    March 2009
    S M T W T F S
    « Feb   May »
    1234567
    891011121314
    15161718192021
    22232425262728
    293031  
    SEO Powered by Platinum SEO from Techblissonline

    Twitter links powered by Tweet This v1.7.4, a WordPress plugin for Twitter.