You are close. You only have to glue them together.
Code:
#!/bin/sh
name=$(ifconfig |grep -E 'flags' |grep -v lo |grep -v enc |awk -F":" '{print $1}')
echo "The interfaces are: $name"
#ip=$(ifconfig |grep -E 'inet' |grep -v inet6 | grep -v 127.0.0.1 |awk '{print $2}')
for X in $name ; do
ip=$(ifconfig $X | grep 'inet ' | awk '{print $2}')
cat <<END
Interface name: $X IP address: $ip
END
done
Set the variable 'name' to the names of the NICs. (Using your grep/awk wizardy)
Just echo this variable to check
Now loop over these names, do an 'ifconfig' for each of them and filter the 'inet ' line to extract the IP address.
The output in my case
Code:
The interfaces are: bge0
re0
Interface name: bge0 IP address:
Interface name: re0 IP address: 192.168.222.20
My ifconfig output:
Code:
$ ifconfiglo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33160
priority: 0
groups: lo
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
bge0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500
lladdr 00:10:18:00:9f:fd
priority: 0
media: Ethernet autoselect (none)
status: no carrier
re0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
lladdr 00:19:db:47:b0:4c
priority: 0
groups: egress
media: Ethernet autoselect (100baseTX full-duplex,rxpause,txpause)
status: active
inet 192.168.222.20 netmask 0xffffff00 broadcast 192.168.222.255
inet6 fe80::219:dbff:fe47:b04c%re0 prefixlen 64 scopeid 0x2
enc0: flags=0<> mtu 1536
priority: 0
pflog0: flags=141<UP,RUNNING,PROMISC> mtu 33160
priority: 0
groups: pflog