How to Post Your Cable/DSL I.P. Address Through a Home Router

The Problem

I wanted me and my friends to be able to contact my computer from a remote location (for FTP, VNC, etc.). The problem is that my Cable Modem I.P. address is not fixed and can change. The problem is compounded by the fact that my computer is on a home networking router and so is unaware of its external I.P. address.

Solution #1 (Existing Software)

There are programs that will allow you to find out your external I.P. address. I looked at many of these problems, but I was not satisfied with any of them. Many would only work from your home computer, leaving it up to you to publish the I.P. yourself. Many required you to sign up for a service. The service may be free, but that just seems overkill. And worst, all these programs are bloated. I hate having to have a 1 Mb+ program running constantly on my computer doing only one little task. If this is the solution for you, such software can be found on any of the online software libraries such as tucows.com. If you are willing to get your hands a little dirty though (metaphorically speaking), keep reading for a better solution.

Solution #2 (Do-it-yourself)

This solution takes a little configuration work, but it works well and can be configured however you like. The solution I present is a specific example of a general idea. No doubt you could improve on the solution and customize it to better suit your needs. Go ahead, I encourage it. If you come up with something good, let me know.

This solution was created using Windows 2000, although it should probably work with other versions of Windows. Follow the steps below to complete your solution.

What You Need Before You Start

  1. You will probably the get best results if you know a little about batch files, the Windows command line and Windows FTP client. Don't let this scare you... you don't need to know much, but it helps.
  2. You will probably want to download the Post-IP Kit that contains the files that you will need. Unzip the file into the directory where you want it installed on your HOME COMPUTER. This will only work from the computer for which you want the I.P. address.
  3. You will need one or two other programs as described below. Both are very small and both are FREE.

Step 1: Find Your I.P. Address

The main file that drives your ip-poster is post-ip.bat. The first thing it does is try to get your I.P. from an external web page. For this to work, you need to specify the web page to get your I.P. address from. This can be a script running on your own (external) web site or any page that will tell you your I.P. address. There are many, and I suggested a few in the ip-websites.txt file in the kit.

Now start configuring your post-ip.bat. This is a batch file in teh kit that exeutes a series of commands. To edit, RIGHT click on the file and click on Edit from the pop-up menu. The part you will be concerned about is the top part with all the set commands. These set variables that are used in the rest of the batch file. Find the set command for POSTIPIN. Set this to the web site address from which you will get your I.P. Also set the variable POSTIPPATH to the directory where you installed the Post-IP kit. Keep post-ip.bat open.

Step 2: Save your I.P. address locally

For this part wou will need a program that will fetch the web page with your I.P. address and save it to you local (home) computer. For this I use wget (open source freeware). This could be found on Google. A URL link is also include in the kit. The nice thing about wget is that it is small and multipurpose. You can use it for this project, but you can also use it to download any web content.

Place the file wget.exe into the directory where you want it installed. Then in post-ip.bat, specify the path to wget for the variable WGETPROG.

Step 3: Publish your I.P. by FTP (Optional)

Once you have your I.P., you need to publish it on a web site where you can access it remotely. If you do not have FTP access to a web site, skip to the next step. Windows 2000 comes with a command line FTP program. To configure it, set the variable FTPHOST in post-ip.bat. Remove the REM before the ftp command line to activate (REM makes the line a comment).

Now you also need to edit the file post-ip.ftp. The top two lines of the file is your ftp username and password. The rest of the file is a list of FTP commands: lcd changes the local directory, cd changes the remote directory and put uploads the file. Set all these commands appropriately and save the file.

Step 4: Publish your I.P. by e-mail (Optional)

To send your I.P. address to your e-mail address, you will need a command line e-mail program. Here I use bmail (freeware) which can be found on Google. I also include a link in the kit. Again, The nice thing about this program is that it is extremely small and it can be used for other applications. Place the file bmail.exe into the directory where you want it installed. Now set the BMAILPROG, BMAILTO and BMAILSMTP variables. Remove the REM before the %BMAILPROG% command line to activate (REM makes the line a comment).

Step 5: Save, Test and Schedule

Save post-ip.bat. You can test it by running the batch file manually by double-clicking on it, or even better, by running it from the command line. If successful, you should see the files ip-post.html and post-ip-log.txt appear in you postip directory. The first is the web page that was downloaded and the second is a log file of the operations performed.

Now that you have it working, you probabaly want to have it run automatically every so often. To do this, we will use the Windows scheduler by entering the following at the command line:

at 9:00AM /EVERY:M,T,W,Th,F,S,Su c:\net\postip\post-ip.bat

This will schedule the batch file to run every day at 9:00AM. Be sure to adjust the path to your post-ip.bat as necessary. You can also run schedule.bat, but edit it first to make the same adjustments. If you need to have it run more than once a day, you can run variations of this command (to have multiple schedules) or use another scheduler (perhaps cron?).

Conclusion

Whew! That took a little work. But you got a good working solution that is FREE! And it is cutomizable to do exactly what you want it to do. Your computer does not need to run a resource hog and you don't have to subscribe to anything. Here are a few ideas for customizing the kit:

Enjoy. If you have comments or suggestions e-mail me.

- Roy P. Johnston, Jr.

http://www.johnstons.org/wdc/pub/resources/pub_ip_howto.html
July 10, 2004