Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'simpler way' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
simpler way
Authored by: Anonymous on May 05, '01 01:37:38PM
just type
ipconfig getifaddr <interfacename>
Where interface name is one of the interfaces listed by typing
ifconfig -a
if you have a broadband or network connection, you're probably using your ethernet connection and your interface name is probably 'en0' (Ethernet card 0)

This method is fast and completely local, i.e. you don't need to go make an HTTP request to get your own IP address.

[ Reply to This | # ]

Authored by: robg on May 05, '01 01:57:18PM
But this seems to only return the internal IP address. What if I want the external IP address? My machine sits behind a hardware router; all my internal IPs are "192.168.1.x", but my public IP is provided by AT&T. So when I hit a web site, the actual value returned is my true IP, not the internal-only (obviously) 192 version. When I tried these commands in my terminal, all that ipconfig getifaddr en0 returned was my "192" address. I don't see any way to pull the public IP from the ipconfig data? -rob.

[ Reply to This | # ]
Authored by: Anonymous on May 06, '01 01:06:07PM

You're right, that will give you the local address. If you're behind a firewall and your address is being translated, the only way I can think of to get your address is to make a request out like you did with wget or a similar utility. That's what many dynamic DNS clients do.

That's assuming you want the external address and it doesn't change. Sometimes firewalls will not give you a 1-to-1 address correlation. The address may change every time you make a connection through the firewall.

[ Reply to This | # ]