Useful bash oneliner: List Server IP Addresses

Gravatar

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


Posted on : Oct 10 2007
Posted under Software Development, cli, linux, web stuff |

4 People have left comments on this post

Oct 10, 2007 - 02:10:52
Gravatar  James Byers said:

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.

Oct 10, 2007 - 03:10:49
Gravatar  apokalyptik said:

indeed! thanks!

Oct 10, 2007 - 07:10:02
Gravatar  Joseph Scott said:

Here’s a FreeBSD version:

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

Oct 10, 2007 - 08:10:39
Gravatar  apokalyptik said:

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