ifconfig is a system administration utility in Unix-like operating systems which presents network interface configuration, including IP addresses, masks, Mac addresses and a lot of other stuff. The ifconfig output may be slightly varying on different operating systems. The utility is very frequently included in shell scripts to get some network parameters. The presented below command supports with different ifconfig formats.
$ ifconfig | grep ‘inet addr:\|inet \|inet6 addr:\|inet6 ‘ | grep -v ‘127.0.0.1\|::1’ | sed ‘s/addr://’ | awk ‘{ print $2}’ 192.168.2.22 fe80::a00:27ff:fe6f:98e1 |