Posts Tagged ‘check’

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

March 27th, 2012 6 comments

Last year I wrote about a little script I use to query for my current IP address from the Linux CLI. dyn’s checker has served me well over the years and has been rock solid stable, which is why I chose it.

A problem has come about however whereby it is returning a private IP address ( which it is taking from the X-Forwarded-For value, rather than ignoring it purely because of the fact that it is a private (internal) IP.

I was trying to find a way to scrape Google’s what is my ip page because it doesn’t suffer from the same bug, and in the process I came about

So here is my new script, in its entirety:

echo -e "\n$(curl -s\n"

If you visit, on the bottom half of the page you will find a handful of other information you could extract. Now let’s hope that sticks around for a while.

Categories: All, Linux

Ternary operator for bash scripting.

January 13th, 2012 2 comments

I was curious whether or not ternary operations are possible in bash or not. It turns out they are but only for numeric comparisons. So what if you wanted to compare whether a string is empty if you cannot use a string comparison (-Z or -n for example)? Use the string’s length.

As always with Linux, there’s a plethora of ways to do what I am doing below, so this is just an example for your reference:

function check_mounted () {
    local result=`df | grep $1`
    echo $((${#result} > 0 ? 1 : 0))
Categories: All, Linux

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