Find your ip with Bash

Page content

I only wanted to run a script if the machine had a specific network access so i constructed this below.

How to find the machines ip address

ifconfig eth0 | grep "inet addr" | awk -F: '{ print $2 }' | awk '{ print $1 }'
Then find out if its on a network we care about
ifconfig eth0 | grep "inet addr" | awk -F: '{ print $2 }' | awk '{ print $1 }' |  grep -qE '172\.24|25\.[0-9]{1,3}\.[0-9]{1,3}' ; echo $?
Another option would be to use facter to get your IP address.