[olug] Unix Tip: GET YOUR IP-ADDRESS
Phil Brutsche
phil at brutsche.us
Fri Mar 21 02:39:18 UTC 2003
Gee, all the fun stuff happens while I'm at work :)
Unix Guru Universe wrote:
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>
>
> UNIX GURU UNIVERSE UNIX HOT TIP
>
> Unix Tip 1905 - March 20, 2003
>
> http://www.ugu.com/sui/ugu/show?tip.today
>
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>
>
>
> GET YOUR IP-ADDRESS
>
> Type this simple command at the unix-prompt
>
> ifconfig | grep "inet addr" | grep -v "127.0.0.1" | awk '{print
> $2;}' | awk -F':' '{print $2;}'
This is similar to another tip that was sent out a month or two ago.
This is the line I use in my iptables scripts, which is a good bit simpler:
/sbin/ifconfig eth0 | awk '/inet/ { print $2 }' | awk -F: '{ print $2 }'
I've also used this one:
/sbin/ifconfig eth0 | awk '/inet/ { print substr ($2, 6, length ($2)) }'
Unfortunately, it's also specific to GNU awk (sadly, the substr()
function behaves differently between the different awk implementations).
--
Phil Brutsche
phil at brutsche.us
More information about the OLUG
mailing list