Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created July 27, 2010 17:57
Show Gist options
  • Select an option

  • Save cowboy/492588 to your computer and use it in GitHub Desktop.

Select an option

Save cowboy/492588 to your computer and use it in GitHub Desktop.
Echo a list of all bound IPs. If an IP is passed, echo that IP if it is currently bound.
#!/bin/bash
# Tested in OS X 10.5
#
# Echo a list of all bound IPs. If an IP is passed, echo that
# IP if it is currently bound.
IPLIST=$(ifconfig -u | grep -w 'inet' | grep -v '127[.]0[.]0[.]1' | cut -d ' ' -f 2 | sed 's/^ *//;s/ *$//')
if [ $1 ]; then
if [ -n "$(echo $IPLIST | grep -w $1)" ]; then
echo $1
fi
else
echo $IPLIST
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment