Posts Tagged ‘ip’

What’s my IP? Check your IP address from the command line.

February 21st, 2011 12 comments

In an attempt to get out of writer’s block, I’m going to post my way of quickly looking up my public IP address from the command line. I know that there is a million ways to do this and thousands out there have a shorter line blah blah… so again, this is just my preference. This came in handy at work the other day when I shared it with a colleague who dropped it into a function in a file under /etc/profile.d/ on mutiple systems we work with. This way, any user of any system can have access to it.

echo -e "\n`wget -nv -O - 2>&1 | \
sed -n -e 's/.*\(.*\).*/\1/p'`\n"

Sample output of the above would be:

Current IP Address:

And of course, if you prefer to get just the IP address itself, it’s a simple modification, just change the sed part to:

sed -n -e 's/.*\(.*\)\s\(.*\).*/\2/p'`\n"

Alternate output:

UPDATE: What is my IP address from the command line, revisited.

Categories: All, Linux