#!perl # check IE "Favorites" looking for link rot # you'll need to run ppm and install Crypt-SSLeay for https support $FAVORITES = 'C:\\Documents and Settings\\rjh\\Favorites'; $|=1; use LWP::UserAgent; $UA = LWP::UserAgent->new; $UA->timeout(5); &parsedir($FAVORITES); open(F,">linkrot.out") || die "write linkrot.out: $!\n"; print F "\n\n"; print F "="x79; print "F \n"; print F "RESULTS\n"; print F "="x79; print F "\n"; foreach $fn (sort keys %RESULTS) { print F "$fn: $RESULTS{$fn}\n"; } close(F); exit 0; sub parsedir { my ($dirname)=@_; print "\n"; my $path = $dirname; $path =~ s/^C:.+Documents and Settings.+rjh.+Favorites\\+//; print "$path:"; opendir(D,$dirname); my @f=grep(!/^\.\.?$/,readdir(D)); closedir(D); # parse the directories first foreach $f (sort @f) { next unless (-d "$dirname\\$f"); &parsedir("$dirname\\$f"); } # parse the link files next foreach $f (sort @f) { next unless (-f "$dirname\\$f"); next if ($f !~ /.*\.url$/i); # skip non-shortcut files &parsefile("$dirname\\$f"); } } sub parsefile { my ($filename)=@_; my $url; my $fn=$filename; $fn=~s/.*\\(.*$)/$1/; $fn=~s/\.url$//; $fn=~s/^\.\\//; print "\n "; if (length($fn) > 40) { print substr($fn,0,40)."...: "; } else { print "$fn: "; } open(F,$filename) || die "read $filename: $!\n"; while () { next unless /^URL/; tr/\r\n//d; ($url=$_)=~s/^URL=//; last; } close(F); $req = HTTP::Request->new(GET => $url); $req->header('Accept' => 'text/html'); $res=$UA->request($req); if ($res->is_success) { print "ok"; } else { print $res->status_line; $RESULTS{$filename}=$res->status_line; } }