#!/usr/bin/perl # njarj.pl : http://njarj.org/contribute.html # typically executed "/usr/local/path/njarj.pl /var/log/maillog*" # or "/usr/local/path/njarj.pl /var/log/messages*" from crontab # may have to run as root to access /var/log files ### Change this section to your specific environment ### #Results file: set to the full path/file-name to store results file use Net::DNS; use IO::File; use IO::Seekable; $filename = "/var/tmp/njabl.txt"; $last_filename = "/var/tmp/njabl.last"; #UID and GID to own results file, from /etc/passwd @fileown = (0,0); #Permissions assigned to results file, usually leave alone $filemod = 0644; my $dns_res = new Net::DNS::Resolver; ### Shouldn't need to change anything else ### #Calculate yesterday's date localtime(time() - 24 * 3600) =~ /^\S+\s+(\S+\s+\S+)\s+/; $date = $1; #track found relays %addrs = (); unlink $filename; open OUTFILE, "> $filename"; my $last_time; open LASTFILE, "< $last_filename"; while () { $last_time=$_; break; } close LASTFILE; print "LastFile: $last_time\n"; my $start_line=0; while ($filein = shift(@ARGV)) { $start_line++; #open the next log file in the list my $fh = new IO::File; $fh = new IO::File "$filein", O_RDONLY; if (!defined($fh)) { die "Unable to open $filein|n"; } #print <$fh>; #$fh->close; #} #open LOGFILE, "< $filein"; while (!$fh->eof) { #only look at sendmail lines from yesterday my $line=$fh->getline; chop($line); if ($line !~ /NOERROR/ ) {next;} #next unless $line (m/NOERROR/o); # 1070013800 216.170.230.21 169.210.199.63.tdsbl.tds.net A IN: NOERROR/1/85 my ($time, $dns_svr, $ip, $a, $in, $error) = $line =~ /(.*) (.*) (.*) (.*) (.*) (.*)/; #if ($last_time ne "" and $time < $last_time) {next; } #$last_time=$time; $ip =~ m/(\d+)\.(\d+)\.(\d+)\.(\d+)\.tdsbl\.tds\.net/; $relay="$4.$3.$2.$1"; my $real_dnsbl_relay="$1.$2.$3.$4.qwdnsbl.njabl.org"; print OUTFILE "NOTE: Checking $real_dnsbl_relay\n" if ($1 and !defined($addrs{$relay})); my $query = $dns_res->search("$real_dnsbl_relay") if ($1 and !defined($addrs{$relay})); #print the relay IP addr if we find a new one print OUTFILE $relay,"\n" if ($1 and !defined($addrs{$relay})); $addrs{$relay} = 1; } my $pos = $fh->tell; print "Ended at pos: $pos Line NUmber: $start_line\n"; close LOGFILE; } close OUTFILE; # Store where I left off open LASTFILE, "> $last_filename"; print LASTFILE "$last_time"; close LASTFILE; #set the file ownership and permissions chown @fileown, $filename; chmod $filemod, $filename; sub check_dns { $res = new Net::DNS::Resolver; my($in_ip)=@_; my $query = $res->search("$in_ip"); }