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

Track a changing IP number remotely Internet
I love this site. By incorporating many past hints, I've developed a simplistic "poor man's" way of getting remote access to a Mac that is behind a router on a dynamic DSL account. Let's say you want to have remote access to your Mac - secure telnet and FTP access for example. If you are like me, you have the following problems:
  1. My DSL connection has a dynamic IP address
  2. My Mac is connected to a router, which gives me a local IP address.
  3. I'm too cheap to buy a domain-name or register for a Dynamic DNS service.
If you'd like the solution to these problems, read the rest of the article...

While the "ifconfig -a" command works great for the local IP address, it doesn't give me the router's IP address to the outside world. However, there is a web-site that provides this service (which I found in a comment at MacOSX Hints). Going to gives you the WAN IP address. The "curl" command allows us to save this page to a file.

Next, we need a convenient place to post this file so you can look-up the current IP address to your computer. The Sites folder in your iDisk will work perfectly. You'll be able to look-up your IP address with a web-browser.

Finally, we need a way to have this file updated on a regular basis. We'll use the "cron" program that was explained a while ago on this site.

Okay, create the following file anywhere in your Home folder:
#       $NetBSD: crontab,v 1.13 1997/10/26 13:36:31 lukem Exp $
# ~/Unix/crontab - my crontab
#min hour mday month wday command
0 * * * * curl>/Volumes/iDisk_name/Sites/myip1234.html
Those are TABS, not spaces. Replace "iDisk_name" with whatever your iDisk is called when mounted. Replace "myip1234.html" with whatever you wish to call the file. If you don't wish to have your IP address advertised, I reccomend you give it a cryptic name--and don't post the link on your web-page ;-). This is set to update the file at the top of every hour. If you like, you can make it update every 30 minutes by replacing "0" with "*/30". Save the file as "mycrontab" or something similar.

Now, mount your iDisk. Open the terminal and cd to the folder where your "mycrontab" file is stored. Type this command:
crontab mycrontab
That's it! From here on you can view the IP address of your remote machine by browsing to or whatever you named the .html file.

Make sure to enable login and FTP through the File-Sharing preferences. I HIGHLY reccomend you use ssh and sftp to connect for security. If you are given a local IP address from a router, your next task will be to forward the telnet and FTP ports from the router to your machine. As this varies with different routers, I'll let you read the directions.

[Editor's note: First, I have not tried this myself, but it seems straightforward. Second, the tip depends on having your iDisk mounted at all times, so you'll have to use the WebDAV method (which has no timeout). Alternatives that come to mind including writing the info to a file and then using an automated FTP client to move it to a web site; mailing it to yourself; etc. Finally, this tip demonstrates an effective use of 'cron' -- cool stuff!]
  • Currently 2.33 / 5
  You rated: 1 / 5 (3 votes cast)

Track a changing IP number remotely | 10 comments | Create New Account
Click here to return to the 'Track a changing IP number remotely' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say. Service is FREE ...
Authored by: Anonymous on Nov 14, '01 10:56:25PM
Better yet, the service at the URL is free, [clipped from the site]
Just get your cable installed? Itching to have a personal site on your DSL? Want to control your own e-mail? Don't want to have to tell friends about that annoying changing IP address or ISP-assigned hostname? We've got the answers for you! Our Dynamic DNS and Static DNS services give you a new name -, for example, or you can choose from several other domains. Sign up, pick a hostname, download one of our selection of third-party update clients, and you're on your way! Best of all, these services are totally free for up to 5 hostnames each. Up to 20 hostnames in each service are available to donators.
Just go to and register; then download a free client (I use DNSUpdate by Julien Jalon) that maintains 'track' of your URL. Both the service and the client take donations (but not obligatory; but you'll want to give something when you see how slick it is ...)

[ Reply to This | # ] Service is FREE ...
Authored by: james_sorenson on Nov 15, '01 02:00:28AM

Well, so it is. However, there may still be uses for this idea.
Perhaps an automatic iDisk backup, or a simple web-mirroring solution?
I also like that I don't have to worry about "DNS trickle time" if I
set crontab to update every 10 minutes or so. In any case, thanks for
the tip.

[ Reply to This | # ]
Better yet
Authored by: phayd on Nov 15, '01 08:57:18AM

Just set your computer to automate a single e-mail when you request it.

Possibly when it sees a message with the subject "IP Address Query - from Bob"

Look at the headers of the message and voila! your address is found.

[ Reply to This | # ]
Sounds familiar
Authored by: po_boy on Nov 15, '01 12:06:13PM

i used to have my linux box do a similar thing, and then mail the address to me at work and to my pager. That got old, so I developed the site at I have since sold it, but I believe that it remains free. It may help you out.

Also, It's my understanding that some DSL modems and/or cable modems will announce their new IP addresses through nsupdates to nameservers, or sometimes through services like (i think it was)

Good luck!


[ Reply to This | # ]
re: Dyndns
Authored by: Jay on Nov 15, '01 12:41:13PM

Dyndns is amazing! I've been using it for a little while now and still can't belive that you can have up to 5 free hostnames. It works great, it's up all the time and I can get to all my stuff all the time. I recommend DNSUpdate (search for keeping your Mac's IP address updated with the dyndns server. It runs as a daemon, so it's pretty much run once and forget it.

[ Reply to This | # ] and Netgear routers
Authored by: Anonymous on Nov 15, '01 01:13:15PM

The Netgear RO 318 Router have a built in client for I use this router on a number of sites and this funktion is really neat. Probably it's in other Netgear models also.

The router itself is very good also, I have had zero problems with it. Everything just works, even Traceroutes och QuickTime streaming via UDP.

[ Reply to This | # ]
more options
Authored by: jfw on Nov 16, '01 08:56:00AM

Instead of a cron job you could write a script that was activated whenever you logged on to write the file (and when you logged out to remove it).

I've heard of people doing same kind of thing using ssh and writing to a file that was accessible to the outside world via http or finger.

[ Reply to This | # ]
Authored by: frogger on Nov 16, '01 01:22:21PM

Here is a script that I use to check my IP, generate a small html page, and ftp it to an external web server. The advantage of this way is not having to have your iDisk mounted all the time. Unfortunately, you cannot access your iDisk via ftp, so this will only work if you have webspace somewhere else.

The ftp script (mentioned in the script below) is just a small text file that feeds instructions to the ftp program. (Mine has only 2 lines: cd public_html; put ipaddress.html -- YMMV) The ftp script is in my home directory.

Put the script listed below in your bin directory and make it executable. When making a crontab to run the script, BE SURE TO PROVIDE THE PATH TO THE SCRIPT. e.g. /Users/yourname/bin/ipscript

When I first set this up, it wouldn't execute without the full path, even though the bin dir is in my path. Oh well.

One last note, I use grep to find the line with the IP address, and instead of XXX I have 3 numbers that never change when I am issued my IP address (the first three).

#Executable script

ip=`curl -s | grep XXX | awk '{print $4}'`

echo "<html><head><title>Current IP Check</title></head>
<body bgcolor=white text=black>
Current IP Address: $ip<br>
<a href="http://$ip">Clickable</a><br><br><b>" > $page
date >> $page
echo '</b><br><br><PRE>' >> $page
who | awk '{print $1}' >> $page
echo '</PRE><br><br><a href=><img src="/images/afunpic.gif"></a>' >> $page
echo '</body></html>' >> $page
ftp < ftpscript

[ Reply to This | # ]
Once more, in Perl
Authored by: ngb on Jan 07, '02 01:22:46PM
Here's a perl version I wrote. I use curl to get the IP address from dyndns and save it to a file so I can keep track of when and how often the number changes. I also use a file for the HTML code so it's not hard-coded into the script.

$rootfilesys = "/Volumes/{Your iDisk}/Sites/";
$ipsource = $rootfilesys."myip.html";
$htmlsource = $rootfilesys."myredirect.html";
$htmldest = $rootfilesys."ipindex.html";

// check that the iDisk is mounted
if (-e $rootfilesys) {
#    print "iDisk is mountedn";
} else {
    die "iDisk not mounted: $!n";

`curl -s -i -o /Volumes/ngb/Sites/myip.html`;

// extract the IP number from the resulting file
open (IP_SOURCE, $ipsource);
while () {
    ($ipnum) = /(d+.d+.d+.d+$)/;
      if (defined($ipnum)) {
close (IP_SOURCE);

open (HTML_SOURCE, $htmlsource);
open (HTML_DEST, ">".$htmldest);
while () {
    print HTML_DEST $_;
close (HTML_DEST);
close (HTML_SOURCE);
I've removed a bunch of error checking code for readability. Mostly checking that the files are opened and closed correctly.

[ Reply to This | # ]
egrep refinement for TMTOWTDI
Authored by: sophistry on Feb 04, '03 05:17:52PM

curl -s | egrep '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | cut -d" " -f4

[ Reply to This | # ]