netmind.pl

    1 | #!/usr/bin/perl
    2 | use Digest::MD5("md5_hex");
    3 | use LWP::UserAgent;
    4 | my$file="netmind.txt";
    5 | my$ua=LWP::UserAgent->new;
    6 | $ua->agent("netmind/3.14\@piology.org");
    7 | 
    8 | # Verify addresses
    9 | my($error,$new);
   10 | open(FILE,"<$file");
   11 | while(<FILE>) {
   12 |   chomp;
   13 |   my($URL,$hash)=split /#/;
   14 |   my$response = $ua->simple_request(HTTP::Request->new(GET=>$URL));
   15 |   if($response->is_success) {
   16 |     my$newhash = md5_hex($response->content);
   17 |     $error.="$URL\n" if($hash && $hash ne $newhash);
   18 |     $new  .="$URL#$newhash\n";
   19 |   } else {
   20 |     $error.="$URL ".$response->code." ".$response->message."\n";
   21 |     if($hash) {$new.="$URL#$hash\n"} else {$new.="$URL\n"}
   22 |   }
   23 | }
   24 | close(FILE);
   25 | 
   26 | # Save new data
   27 | rename($file,"$file.bak");
   28 | open  (FILE,">$file");
   29 | print (FILE $new);
   30 | close (FILE);
   31 | chmod (0600,$file);
   32 | 
   33 | # Output changes
   34 | print $error if($error);

Valid CSS!Valid HTML 4.01!
© Boris 'pi' Piwinger, June 26, 2001