Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sonofslim

macrumors 6502a
Original poster
Jun 6, 2003
742
0
is there a terminal command that will display your external IP address? ifconfig and netstat only seem to report my local/network address, so i've been using curl and awk to parse http://checkip.dyndns.org. but i'd prefer a way that doesn't rely on an http call. not to mention that my method will fail if/when dyndns changes the format of that page.

any ideas?
 
sonofslim said:
is there a terminal command that will display your external IP address? ifconfig and netstat only seem to report my local/network address

I'm a bit confused - are you behind a NAT firewall? ifconfig should report your IP address just fine.

I realize this is just nit-picking, but if your NAT-ted then what you're probably looking for is the IP of the router/firewall rather than your own. If that's the case you can usually get it from the router's Web interface (assuming it has one, and most do).
 
Westside guy said:
but if your NAT-ted then what you're probably looking for is the IP of the router/firewall rather than your own.

yes, that's the case. is there any way to get my router's external IP address from the terminal?
 
I think your best bet is to do a traceroute of a packet ping (so it sends back to you). This will report both the outgoing (not too helpful) and return trip (where you will find your IP).

BEN
 
try ifconfig

yes ifconfig, not ipconfig

Here is a more detailed look at network commands for UNIX, LINUX, and DOS.
 
GigaWire said:
try ifconfig

see above: ifconfig gives me my local network IP. but the link you sent was pretty helpful -- thanks.

saabmp3 said:
do a traceroute of a packet ping

sorry, i can't figure out how to combine traceroute & ping... any clues?
 
try this in a console window (ensure that cURL is installed) :

Code:
curl -s http://checkip.dyndns.org | sed 's/[a-zA-Z/<> :]//g'
 
Help

Six year old thread. You win! :D

Yes, it is six years old, but as the original poster asked, is there a way, from behind an Airport Extreme, Express, or Time Capsule, to determine your WAN IP address, without relying on an external source, such as checkip.dyndns.org or whatsmyip.com?

It has been six years and maybe something has come around that will now help us to do this?

I appreciate any suggestions on accomplishing this locally as originally asked.
 
Try this:


curl ifconfig.me/all/json

Perfect! Now I can create a shell script to parse the external address and compare it to a saved address without having to bother whatismyip.com with unnecessary calls. I appreciate it! :D
 
Perfect! Now I can create a shell script to parse the external address and compare it to a saved address without having to bother whatismyip.com with unnecessary calls. I appreciate it! :D
Instead, you're "bothering" ifconfig.me as it's a website too. What's the difference?
 
Instead, you're "bothering" ifconfig.me as it's a website too. What's the difference?

I did not realize that. I thought the ifconfig.me was just a function of the ifconfig command.

That still doesn't do what I want then, nor the original poster. I'll keep looking. Thank you for your response.
 
Instead, you're "bothering" ifconfig.me as it's a website too. What's the difference?

Ok, after doing some more research, I have found a way to get the external IP address from an Airport Extreme or Time Capsule (which is what I have) and I don't see why this wouldn't work for any other router that supports SNMP.

From the terminal do this:

prompt$ snmpwalk -Os -c {community name assigned to your device} -v 1 {private ip i.e. 192.168.1.1} ipAdEntAddr

The result for me is:
ipAdrEnt.xxx.xxx.xxx.xxx = IpAddress: xxx.xxx.xxx.xxx
ipAdrEnt.127.0.0.1 = IpAddress: 127.0.0.1
ipAdrEnt.127.0.0.2 = IpAddress: 127.0.0.2
ipAdrEnt.169.254.12.117 = IpAddress: 169.254.12.117
ipAdrEnt.192.168.1.1 = IpAddress: 192.168.1.1

Now all I need to do is parse this the way I want it and I no longer have to ping an external web site to determine my own external IP address.

I believe this answers the original posters question.
 
The reply to this question is there are no such terminal command and/or software of OS that can tell your external IP address (i.e. your "location" in internet) without using external resources (e.g. some other computers).

The reason is simple. It's like asking from your computer where it's located without plugging it in to the internet..
When the computer was just manufactured in the factory and OS was just clean installed on it, it doesn't know your IP address, before you buy this particular computer.. what if someone else bought this particular computer? that would mean that any picked computer has to know all existing external IP addresses and intelligently decide which IP belongs to which guy and also keep in mind that that guy's ISP also changes it from time to time...

That's why you use another server to "bounce" your IP address from as in:
http://www.whatismyip.com
or
curl ifconfig.me/all/json

You also can write a program, which you will be able to run in terminal by just one word, but it still will have to use "external" resources to find out about your external ip address..
 
The reply to this question is there are no such terminal command and/or software of OS that can tell your external IP address (i.e. your "location" in internet) without using external resources (e.g. some other computers).

You are partially correct in that you do need an external resource other than the computer. In my case it is my SNMP compatible router.

What the original poster wanted to do was similar to what I have been successful at. I wanted/needed my router's external IP address and I need to check the IP periodically because my router does not support the dynamic IP service I use. Rather than using http calls and creating traffic (albeit minimal) I wanted something internal to my network that would be able to determine whether or not my dynamic IP address has changed and if so I then reach out to my registrar and update the DNS with the new IP address.

I don't think (my assumption) the OP was asking how to determine the Internet IP address (location) of a computer that has been purchased, set up, and turned on for the first time without connecting it to the Internet.
 
ok, i know this is an old thread, but this same problem put me through a lot of grief.
this is the best I can do cleanly... it only relies on my ISP to respond to a ping (a very small one too!).

#!/bin/bash
ISP=`traceroute -M 2 -m 2 -n -q 1 8.8.8.8 | grep -m 1 -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'`
extIP=`ping -R -c 1 -t 1 -s 1 -n $ISP | grep RR | grep -m 1 -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'`
echo $extIP



The only other way to do this without relying on any external servers is to get it from curl'ing your modem's status page... I've done this successfully with our frontier DSL modem, but it's dirty, slow, unreliable, and requires hard-coding your modem's password. Here's the "process" for that:

curl http://[user]:[password]@[modem's LAN address]/[status.html] | grep 'WanIPAddress=' | grep -m 1 -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
That fetches the raw html, searches for any lines containing "WanIpAddress =" (change that so it's appropriate for your modem's results), and then narrows down those results to an IPv4 style address.


Have fun!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.