This is a website which tracks the IP numbers of a group of people for reference. This is convenient when you want to give someone your IP so they can connect to you for downloads, or for you to connect to your home computer to get files when your away. Just in case your IP changes while your gone. This is a run through of how I setup the IP Tracking site, for those who want to make thier own.

Table of Contents:
There are three parts to setting up the IP Tracking site.
Part 1: Acquiring the IPPart 2: FTP-ing the IPPart 3: Displaying the IPs


 


Back to Main Page Current Page
Basic Operation:


The way this works is the computers you want to track send thier IP numbers to the website in small text files. The webpage reads the IP numbers from the files and displays them on the webpage. The computers use FTP to send the IP text file so the site that hosts the webpage needs to have FTP support. The webpage uses Javascript to read the IP text files, so the site can be designed any way you want to display the numbers.

 

    Templates:
    Here are templates for Parts 1 & 2 to download. They contain the needed Windows command line programs and example configuration files for updating your IP Tracking site. The directory you put them in must be 8 characters or less in length, the cut command can not handle the last directory name in the path being a long name.



    Directly Connected Template:Indirectly Connected Template:
    WindowsWindows

    Part 1: Aquiring the IP
    Depending upon the operating system and whether the computer has a direct connection to the Internet there are different methods to aquire the IP number.
 
           Directly Connected Method:
    Download Template

      If your computer is directly connected to the internet the the IP number we want to extract is assigned to an adapter on your computer.


      Windows:

      The method of acquiring the IP from the current computer was developed in Linux, so when I wanted to do it in Windows I used the same method. I didn't have many tools in DOS to work with, so I had to find ports and non-standard command line executables to get the job done. These tools are all free and available in the templates.

      To extract the IP number we call 'ipconfig' to display the settings of the adapter on the computer, pipe it to 'find' to extract the line that contains the IP number, then pipe it to 'cut' to get the ip number by itself and dump it into a text file.
      ipconfig | find "IP Address" | cut -d":" -f2 > yourIP.txt


      If you have multiple adapters then use 'hostinfo' tool to isolate the external IP.
      hostinfo | find "protocol #" | cut -d":" -f4 > yourIP.txt

      *NIX:
      In Unix based machines we use 'ifconfig' and specify the adapter name to get the adapter information. Grep the line we want and cut the IP number out. We cut twice because there is no single delimiter to isolate the IP.
      ifconfig eth# | grep "inet addr" | cut -d: -f2 | cut -d" " -f1 > yourIP

 


 
           Indirectly Connected Method: Download Template

      If you are behind a firewall or hardware router then the IP of your computer is not the external IP. The easiest way to get the external IP is to use a site like "whatismyip.com" or "checkip.dyndns.org".

      Windows:

      To extract the IP number we use a port of a GNU text-based web browser (lynx) to load the page, pipe the webpage text to 'find' to extract the line containing the IP number, then use 'cut' to get just the IP number and dump it to a text file.
      lynx -dump http://www.whatismyip.com | find "IP is" | cut -d" " -f4 > yourIP.txt

      *NIX:
      Though it's odd in small LANs it is possible to have a Unix based computer behind a firewall and in this case the folllowing method is used to extract external IP number. Use a text-based web browser that can dump the webpage text and pipe it to grep. Use grep to extract the line containing the IP number and use cut to get just the IP number.
      lynx -dump http://www.whatismyip.com | grep "IP is" | cut -d" " -f4 > yourIP
 

    Part 2: FTP-ing the IP
    The text files we just created contain the IP number, now they need to be FTP-ed to the IP Tracking site. They can be sent on demand or set to update on a schedule. If your method uses an outside source to get its IP, we do not we to schedule the updates too frequently out of respect to the outside source that we get our IP from.
    It can be setup to check if the IP number on your computer has changed and if it has then update the site, but that is a little too much to get into here.
 
      Scheduling FTP Updates in Windows: 
      Windows FTP can be told to use a configuration file to get the username, password, and commands to perform. This is how we will configure Windows FTP to send the IP file to our IP Tracking site. The FTP config file named 'iptrack.cfg' should look like this:
      <username>
      <password>
      <"cd /pub..." if you need to change directory>
      put yourIP.txt
      quit

      We tell Windows FTP to use the configuration file we just made by calling it like:
      ftp -s:iptrack.cfg ftp.yourIPTrackingSite.net > iptrack.log
      It is dumped into 'iptrack.log' to suppress the text output of Windows FTP and give us a way to check whether the last update was successful.

      Part 1 and Part 2 are put into a batch (.bat) file 'iptrack.bat':
      @echo off
      REM extract IP from 'ipconfig' if this computer is directly connected to inet
      REM ipconfig | find "IP Address" | cut -d":" -f2 > yourIP.txt

      REM extract IP from whatismyip.com if this computer is not directly connected
      lynx -dump http://www.whatismyip.com | find "IP is" | cut -d" " -f4 > yourIP.txt

      REM Upload IP number to website
      ftp -s:iptrack.cfg ftp.yourIPTrackingSite.net > iptrack.log


      To set it on a schedule, add the batch file to "Scheduled Tasks" in the Control Panel. Set it to update twice a day, or once a week, whatever you want depending upon the reliability of your IP and whether or not you have to use an outside source to get your IP number. To run it manually, simply run the 'iptrack.bat' when you want to update.
 
      Scheduling FTP Updates in *NIX:
      In Unix based systems cron jobs are used to run tasks at scheduled times. We will impliment Part 1 and Part 2 in a cron job to update your IP to the IP Tracking site. I use NCFTP as my FTP client in Linux. To update the site with our IP we call it like this:
      ncftpput -u username -p password -V ftp.yourIPTrackingSite.net yourIP

      Type 'crontab -e' to edit your cron jobs. Add Part1 and Part 2 to the cron job. It should look like this:
      #Extract IP from adapter if this computer is Directly connected
      0 0 * * *
      ifconfig eth# | grep "inet" | cut -d: -f2 | cut -d" " -f1 > yourIP

      #Extract IP from website if this computer is Indirectly connected
      #0 0 * * * lynx -dump whatismyip.com | grep "IP is" | cut -d" " -f4 > yourIP


      #Two minutes later, update site for IP tracking
      2 0 * * * ncftpput -u user -p pass -V ftp.yourIPTrackingSite.net yourIP


      This will run the updates once a day at midnight.
 

    Part 3: Displaying the IP
    The text files are on your IP tracking site, now we have to load the IP numbers from the text files and display them on the webpage. This is done using Javascript. Before we start I should note that each text file that is sent by each person should be a different name so that we know which IP text file belongs to which person. Let's say that Bob send his IP number in a text file named 'bobIP' then you create a text box on the webpage named 'bobTxt'

    First we create a text box for each person sending thier IP number. Name the text boxes so we know which IP number to load into which text box like we did for Bob and put a label by the text box to show who's IP it is.


    In the opening <body> tag of the webpage we add an 'onload' inside the body tag itself. You can add multiple 'onload's by seperating them with semi-colons. Make sure all of the onloads are within the opening body tag. For Bob it would look like this:
    <body onload="window.bobFile.location = 'bobIP'; window.nextPerson.location = ..." >
    This tells the page what file Bob's IP is in.

    In the <script> section of the webpage add a Javascript function for each text box. This function will extract the text out of the IP file we specified above and put it into the text box. For Bob the function would be:
     function showBob() 
     {
       var bobIP = window.bobFile.document.body.innerHTML.replace(/\<[^\>]+\>/gm, "");
       if(bobIP > "")
         form.bobTxt.value=bobIP;
     }

    Then at the very end of the <form> section of the webpage, just before the </form> we add an <iframe> for each person. This will call the functions above and display the IP numbers in the text boxes on the webpage. It is placed at the bottom of the <form> section so that all of the webpage is loaded before the functions are called. This way the functions don't try to put the IP numbers in text boxes that have not been loaded yet. For Bob it would look like:
    <iframe id="bobFile" style="display:none" onload="showBob()"> </iframe>

    Now the text boxes are setup in the webpage, so you can move them around and design the webpage around them however you want. We are done. §