IP address

The IP address is often used to mean “all a machine’s IP addresses” or “all network interfaces”. If you configure a server to listen to it listens on everything. If you specify as some sort of IP restricting filter it usually applies to all addresses.

But what does mean to a client? Surprisingly, connecting to seems to work on both my Macs and Linux. On my Mac “route get” shows me it’s going to use my Ethernet interface, with a real IP address. On my Linux box “ip route get” shows it using the loopback on

Looking at this because I need a shell script that prints out an IP address that is likely to work even if I’m remotely shelled in to something. Here’s a script I use to launch test web servers for webapp development:

function pws {
  [ -z "$PORT" ] && PORT=$[RANDOM%1000 + 9000]
  IP=`ifconfig | awk '/inet / { if ($2 != "") { print $2; exit 0; } }'`
  python -m CGIHTTPServer "$PORT" >> /tmp/pws-"$PORT".log 2>&1 &
  echo "http://$IP:$PORT/"