Parse ifconfig to extract IPv4 and IPv6

By | June 25, 2017

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 ‘\|::1’ | sed ‘s/addr://’ | awk ‘{ print $2}’

Leave a Reply

Your email address will not be published. Required fields are marked *