'ifconfig' to skip loopback IPs

I generally use

/usr/sbin/ifconfig -a | grep "inet" |egrep -v "inet6|0.0.0.0|192.168.100.2"|awk '{print $2}'

to capture IPs on a host.

Now here is what i have:

bash-2.05$  /usr/sbin/ifconfig -a
lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
        inet <IP> netmask ff000000
lo0:1: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
        inet <IP> netmask ff000000
lo0:2: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
        inet <IP> netmask fffffff8
lo0:3: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
        inet <IP> netmask fffffff8
lo0:4: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
        inet <IP> netmask fffffff8
lo0:5: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
        inet <IP> netmask fffffff8
lo0:6: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
        inet <IP> netmask fffffff8
lo0:7: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
        inet <IP> netmask fffffff8
lo0:8: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
        inet <IP> netmask fffffff8
ce0: flags=9040843<UP,BROADCAST,RUNNING,MULTICAST,DEPRECATED,IPv4,NOFAILOVER> mtu 1500 index 2
        inet <IP> netmask ffffff80 broadcast <BROADCAST>
        groupname ipmp
ce0:1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
        inet <IP> netmask ffffff80 broadcast <BROADCAST>
ce1: flags=9040843<UP,BROADCAST,RUNNING,MULTICAST,DEPRECATED,IPv4,NOFAILOVER> mtu 1500 index 3
        inet <IP> netmask ffffff80 broadcast <BROADCAST>
        groupname ipmp
ce1:1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 3
        inet <IP> netmask ffffff80 broadcast <BROADCAST>
ce5: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 4
        inet <IP> netmask fffffc00 broadcast <BROADCAST>

As you can see,i have multiple loopbacks configured.I wish not to capture these IP addresses.I just want it to capture IP address which are not loopback i.e in above example..IPs for 'ceo'...etc...

Kindly advice

Abhi

What kind of system is this? On linux, you may be able to avoid it outputting the unwanted network devices entirely:

ls /sys/class/net | egrep -v "^(lo[0-9]?|sit[0-9]|ce[0-9]?)$" | xargs --max-args=1 /sbin/ifconfig

I need a command or a small script for all three platforms : AIX,Solaris and Linux.

Abhi

just add

grep -v '^lo'
grep -v '^lo'

this will just chop off first line....

it will still display second line where IP is present.

Look at this:

bash-3.00$  /usr/sbin/ifconfig -a
lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
        inet 127.0.0.1 netmask ff000000

Line in BOLD will still remain

Regards
Abhi

AK835, I realized that later on.. thanks.

Here is what I use under Solaris, it skips interfaces used by zones too:

ifconfig -a4 | nawk '
  BEGIN { ignore=0 }
  /^lo/ { ignore=1 }
  /zone/ { ignore=1 }
  /inet/ { if((ignore==0) && ($2!="0.0.0.0")) print $2 ; ignore=0}
  '

thanks jlliagre ..!!

that is what i wanted ....!!

FYI/U
here is what i use to skip loopback interfaces and extract a list :

/usr/sbin/ifconfig -a | nawk '$1 ~ /:$/ && $1 !~ /^lo/ {sub(":$", "", $1); print $1}'

thanks everyone...!!

Regards
Abhi