This little script will give you the ipv4 address for a given network interface, or list all of them if you leave the parameter blank:



/sbin/ifconfig $INTERFACE | grep “inet addr” | cut -d\: -f 2 | cut -d” ” -f 1

Call it like this:

~/bin/interface2addr eth0

3 thoughts on “interface2addr

  1. Unless you use non english locale. So you may want to use:
    LANG= /sbin/ifconfig $INTERFACE | grep “inet addr” | cut -d\: -f 2 | cut -d” ” -f 1

  2. “inet addr” is translated if locale is set. In Czech it is “inet adr”, which is quite similar, but other languages can have it translated very differently.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.