Linux.com

Get a list of your interface addresses

Posted by: Administrator on January 16, 2006 07:23 PM
I played around, and got this so far:
<nobr> <wbr></nobr>
<tt>/sbin/ifconfig | awk '/HWaddr/ { change = 1; interface = $1 }<nobr> <wbr></nobr>/inet<nobr> <wbr></nobr>/{ change = 2; iface = $2; split( iface, ifacedet, ":" ); ifaceadr = ifacedet[2];  } { if( change == 2 ) print interface" = "ifaceadr; change = 0; }'</tt>
Output (my machine):
<tt>eth0 = 10.203.62.82
eth0 = 127.0.0.1
vmnet1 = 192.168.34.1
vmnet8 = 192.168.216.1</tt>
This is 100% correct, but I'm wondering if there's a shorter way - using awk?

#

Return to CLI Magic: Learn to talk awk