Get the ip address in a shell script

# get IP address of eth0 network interface
ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}'

source

3 Comments

Mr XharkJanuary 13th, 2010 at 14:12

Doesn’t work with french distributions.
Correction : ifconfig eth0 | awk ‘/inet adr/ {split ($2,A,”:”); print A[2]}’

‘addr’ => ‘adr’

skanxJanuary 13th, 2010 at 14:20

Ok, but who on earth uses french locales? ;-)

Mr XharkJanuary 13th, 2010 at 19:17

Et bien moi :) of course ^^

Leave a comment

Your comment