IP address

If you are in a DHCP situation and find your IP address frequently changing, here is an easy way to determine it:
ipconfig getifaddr en0
and an alternate (albeit more convoluted method):
ifconfig en0 inet | grep 'inet ' | awk '{print $2}'

If you are behind a router and need your external IP address, issue this command:
wget -q -O /dev/stdout http://checkip.dyndns.org/ | grep 'Current IP Address: ' | awk '{print $4}'
(Of course, you would have to have wget installed in order for this to work.)

Here is a shell script for checking your IP address and logging the results to a file:
Code:
#!/bin/sh
#initialize variable
IP=`wget -q -O /dev/stdout http://checkip.dyndns.org/ | grep 'Current IP Address: ' | awk '{print $4}'`
# prints current IP to shell
echo $IP
#log it
date >> /private/var/log/ip.log
echo $IP >> /private/var/log/ip.log
This script could be added to your crontab in order to check your IP address periodically and log the results to a file.
 
I'm lazy, I have an alias:

alias ip="ifconfig en0 | grep 'inet '"

it gives you useful output for configuring other systems, in addition to your own IP address:

inet 192.168.1.105 netmask 0xffffff00 broadcast 192.168.1.255

Note the trailing space in the 'inet ' pattern!
 
Back
Top