Thatbytes

Mostly Interesting

Find Your Ip With Bash

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

1
ifconfig eth0 | grep "inet addr" | awk -F: '{ print $2 }' | awk '{ print $1 }'

Then find out if its on a network we care about

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

Comments