#!/usr/sbin/perl
#
# v020527 by Litil Divil <ldivil@efnet.org>
# This script is rather agressive! Beware..
#
# KNOW BUGS:
# something to do with lalala.co.uk or dkdkdk.net.ru domains
# or something like that =p
#
die "Usage: perl $0 \"<reason>\"\n" if (!$ARGV[0]);
while (<STDIN>) {
 chomp;
 foreach $word (split(/\s/)) {
  if ($word =~ /[\~a-z0-9\*\.\^]+\@([a-z0-9\-\.]+)/i && !exists($dupe{$1})) {
   $dupe{($host = $1)} = 1;
   $host =~ tr/A-Z/a-z/;
   if ($host =~ /ppp|dialup|dip|slip|dhcp|dyn|ipt.aol/) {
    print "/quote kline 1440 *\@$host :$ARGV[0]\n";
   } else {
    if (($host =~ /([\w\-\.]*)\.([\w\-]+)\.[\w\-]+\.[a-z]{1,5}$/) && !($host =~ /dsl|cable|^.*\d.*\./)) {
     $fh = $1;
     $sh = $2;
     if ($host =~ /\.(com?|net|org|ac|edu)\.[a-z]{2}$/) {
      $host =~ s/$fh/\*/i;
     } else {
      $host =~ s/$fh\.$sh/\*/i;
     }
    } elsif (!($host =~ /^24\./)) {
     $host =~ s/\d+$/\*/;
    }
    print "/quote kline *\@$host :$ARGV[0]\n";
   }
  }
 }
}
