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


Click here to return to the 'Keeping a Historical List of IPs' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Keeping a Historical List of IPs
Authored by: MartySells on Oct 29, '04 03:08:09AM
One thing I added to my implementation of this type of script is a feature that keeps a historical log of when each IP was in use. This is handy if you get asked what your IP was on a particular date or if you want to have an idea of how long your dynamic IPs last.

First, a script that I call iplog (you will have to fix the absolute path but be sure to keep the double >>):

  #!/bin/sh
  DATE=`date +%F,%T`
  EPOCH=`date +%s`
  IP=`curl -s 'checkip.dyndns.org' | tr -C -d '0-9.'`
  echo $IP,$EPOCH,$DATE >> /Users/msells/ip-log.txt
Then something like
  @hourly /Users/msells/bin/iplog
in your crontab.

This can run along side whatever other (email me, create a web page, etc..) solution you use to notify you of changes to your IP address - it's just keeping a local log of what IP was in use. The log file itself is three comma separated fields: IP, seconds since epoch and a human readable datestamp. Accordingly, here are some handy things:

  alias myip='tail -1 /Users/msells/ip-log.txt | cut -d, -f1'
  alias iphistory='cut -d, -f1 /Users/msells/ip-log.txt | uniq -c | tail -5'
The first column in the iphistory is the number of periods (hours in this example) that the given IP was in use with the last one listed being the current IP.

If you want to setup your own CGI that tells you your current IP here's how to in various scripting languages:

  #!/bin/sh
  echo 'Content-type: text/html'
  echo
  echo $REMOTE_ADDR

  #!/usr/bin/perl
  print "Content-type: text/html\n\n" . $ENV{'REMOTE_ADDR'} . "\n";

These, of course, go on an Internet exposed web server with a fixed address, not your local system.

-m

[ Reply to This | # ]