Download the scripts (4KB download), and install them wherever you like. The first script, functions.sh, contains the functions that I use in the second file, ipinfo.sh. Be sure to alter the second line of the ipinfo.sh file to point to the correct location of functions.sh.
When you run ipinfo.sh from the command line, you will receive output similar to the following:
--------------------------------------------------------
Public: xxx.xxx.xxx.xxx
Loopback: 127.0.0.1 / 255.0.0.0
Airport: 10.2.0.168 / 255.255.255.0
Gateway: 10.2.0.1
Domain: yourdomain.com
Nameserver: 10.1.0.50
Nameserver: 192.168.1.16
--------------------------------------------------------
I split the functions out of the main script to I could use them in my bashrc file individually. The functions are as follows:
get_public, get_ip, get_mask, get_gateway, get_dns, get_domain
The get_ip and get_mask functions take a single argument of an interface name (lo0, en0, en1, fw0, etc.). After these are added to my shell environment, I can do things like ping $(get_gateway) or get_ip en1.
[robg adds: These scripts worked as described in my testing. Remember to make ipinfo.sh executable via chmod 755 ipinfo.sh.]

