Skip to content

Instantly share code, notes, and snippets.

@tlehman
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tlehman/b909c6c8dbc55596e48c to your computer and use it in GitHub Desktop.
Save tlehman/b909c6c8dbc55596e48c to your computer and use it in GitHub Desktop.
Just IP addresses
#!/bin/bash
# extract IP addresses from ifconfig command using Perl
if [ "$1" = "-v6" ]; then
ifconfig | perl -ne '/inet6 addr: (([0-9a-f]*:?)*\/\d+)/ && print "$1\n"'
else
ifconfig | perl -ne '/addr:((\d{1,3}\.?){4})/ && print "$1\n"'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment