#!/usr/bin/perl # (C) 2006 Julian Haight (http://www.julianhaight.com) GPL License use strict; my($usage) = q{ NAME bait - encode or decode ip and timestamp SYNOPSIS @s.example.com"> bait 0A000001-4432ba6f DESCRIPTION Script can be used in two modes - First, as a CGI script from within an html page to generate a hex code for the client IP address and timestamp. Install in cgi-bin directory (or similar) and then link into pages with, for example, server-parsed HTML like so: @s.example.com" >  Second, as a command-line utility or CGI to decode a given hex code back into it's component IP address and time. $ bait 0A000001-4432ba6f Bait 0A000001-4432ba6f: Harvested on: Tue Apr 4 14:26:55 2006 By: 10.0.0.1 }; if ($ENV{'REMOTE_ADDR'}) { showBait(); } elsif ($ARGV[0]) { decodeBait($ARGV[0]); } else { print $usage; } exit 0; sub showBait { print 'Content-type: text/html ' . sprintf('%x', unpack ('N', (pack('C4', split(/\./, $ENV{'REMOTE_ADDR'}))))) . '-' . sprintf('%x', time()); } sub decodeBait { use Socket; my($ip, $time) = split('-', $_[0]); print 'Bait ' . $_[0] . ': Harvested on: ' . localtime(unpack('N', pack('H8', $time))) . ' By: ' . join('.', unpack('C4', pack('H8', $ip))) . ' '; }