Useful bash oneliner: List Server IP Addresses

for i in $(/sbin/ifconfig | grep addr: | cut -d’:’ -f2 | cut -d’ ‘ -f1 | grep -Ev ‘^$’); do echo -n $i”, “; done | sed -r s/’, $’/”/g; echo

Comments (5)

  1. James Byers wrote::

    Looks like "done" turned into "one". I needed the same one-liner a while back, based it on ip:

    /sbin/ip addr list | sed -n 's/inet (.*)/.*/1,/p' | xargs | sed 's/,$//'

    Amazing it takes stuff like this to get a list of IPs.

    Wednesday, October 10, 2007 at 6:23 AM #
  2. apokalyptik wrote::

    indeed! thanks!

    Wednesday, October 10, 2007 at 7:44 AM #
  3. Joseph Scott wrote::

    Here's a FreeBSD version:

    /sbin/ifconfig -a | /usr/bin/grep netmask | /usr/bin/awk '{print $2}'

    Wednesday, October 10, 2007 at 11:50 AM #
  4. apokalyptik wrote::

    This is what I love about the *nix way of life. there's always so many ways of doing things. What differentiates the men from the boys (as it were) is not how something gets done but that something gets done. :D

    Wednesday, October 10, 2007 at 12:52 PM #
  5. Gowtham wrote::

    Here's one more (worked on CentOS/Fedora/RedHat-like distros):

    /sbin/ifconfig [OPTIONAL_DEVICE_NAME] | grep "Bcast" | awk -F ' ' '{print $2}' | awk -F ':' '{print $2}'

    -g

    Monday, October 20, 2008 at 2:57 AM #