Originally posted by fortepianissimo:
Thank you, but this has two problems:
1. it relies on an external site (what if the site is down?);
2. it doesn't work behind an NAT'ed machine (i.e., in a home LAN I might want to know the masq'ed IP, not the IP of the gateway connecting to the external world).
It is a little unclear what it is you actually want. Usually, "the IP address of the DEFAULT outward connection" is the default gateway. IOW on a LAN where all the IPs of the LAN machines are in some private range (such as 192.168.1.1 - 192.168.1.254) each of the machines with one or more of those IPs will have to know how to talk to the outside world... not just each other.
If you have a router... it will most likely have an "internal" IP within the range listed above (not always). For instance, on my home network my router has the IP address 192.168.1.253. I actually have more than one router BUT all machines use the one that has the .253 IP. For the internal machines on the LAN they all point to 192.168.1.253 as their default gateway.
The router, naturally, has at least two IPs and at least two interfaces (NICs). Each interface has an IP assigned to it.
Now... on the internal machines (clients), the ones on your LAN... they will have their IP addresses either statically assigned or dynamically assigned (via DHCP). Usually the dynamic IP comes from the router (the router is a DHCP server). The LAN machines also get their default gateway IP and DNS IPs from the DHCP server on the router. It doesn't have to be this way but it usually is this way. You could have a separate DHCP server on the LAN (as I do). In either case... the usual setup for the LAN clients is they get their IP address, default gateway, and DNS IPs from the DHCP server.
On most home LANs the router behaves similarly. It gets its *external* IP address, default gateway, and DNS IPs from your ISPs DHCP server... the *internal* IP address of the router is usually static (typically 192.168.1.1). Depending on how the router is set up and how the ISP does things the *external* IP, default gateway, and DNS IPs may change over time and the router may or may not update this information as the ISP makes changes. It does this via DHCP.
How to determine what is going on....
For your internal Mac OS X clients:
* To determine client IP address(es):
ifconfig -a
which will give you the IP address of all interfaces on the client machine.
* To determine client routing table:
netstat -r
which will tell you how packets are routed to/from the client machine. See the manpage for netstat for all the details. Usually the default gateway is the first entry in the list.
For your router (if you have access):
* You will need access to the router. If your router is a Mac OS X machine then you can use the same commands as above.
* If it is a dedicated appliance router/switch then access is usually via a web interface... just browse to it. Consult your router manual on how to look up the info you need.
For your router (if you DON'T have access):
* If you do not have access to the router or it is a really dumb router it will be a bit more difficult to figure out what the *external* IP address of the router is. Many Unix based systems (Linux/BSD/Mac OS X/Solaris/etc) have a simple utility such as "w". Just ssh to an external Unix based host and type a single w at the prompt and it will tell you who is logged on and from *where*. The *where* part is under the "From" column and is either a fully qualified domain name or an IP address.
* If you are trying to figure out the *external* address of the router AND you are not on your home LAN... say, somwhere out in the world... then ssh to a system that you recently accessed via ssh *from* your home LAN and, depending on the system, it will give you the IP or FQDN that you last sshed from. Alternatively just type "last" and it will give you a list of IPs/FQDNs that you last logged in from.
Note: For "dumb" or inaccessible routers the above methods are kinda kludgy but they do work. There are may be many other methods... even slicker ones.
Hope that helps.