/*_____________________________________________________________________________ |/ / SpamCalc add-on by David "Saturn" van Moolenbroek | Version 0.1, released 23-12-2003 -- support on #help.script/Quakenet | Use/modify however you want, but please keep my name in it. Thank you! | | Keywords: spamcalc, dnsspam, hashtables, regex, files | | This is a port of SpamCalc 0.7.0, and specifically SpamCalc.pm 1.3, a Perl | script by Joost "Garion" Vunderink (http://www.spamcalc.net). Based on a | set of tests on a hostname, it can generate a number that indicates the | level of DNS pollution of that hostname. A higher number means more spam, | and a value of 100 or above means the hostname is definitely DNS spam. For | more information, visit http://www.spamcalc.net and http://www.dnsspam.nl. | | In order for this script to work, you need to download all the files from | http://spamcalc.net/data/ and put them in a subdirectory named "data" | relative to the script (see the "datadir" alias below), before loading the | script. If you had loaded the script, restart mIRC to make the script load | the new data. | | The script defines the following commands/identifiers: | | /spamcalc | | Calculates and displays the SpamCalc value for the given hostname. | | $spamcalc(hostname) | | Calculates and returns the SpamCalc value for the given hostname. | | Simple example | | on @!*:JOIN:#:if ($spamcalc($site) >= 100) ban -k $chan $nick 4 DNS spam \ _\_____________________________________________________________________________ */ alias -l datadir return " $+ $scriptdir $+ data" alias -l max return $iif($1 > $2,$1,$2) alias -l min return $iif($1 < $2,$1,$2) on *:START:init alias -l add { var %i = $lines($3-), %s while (%i) { if (($2) && ($regex($read($3-,n,%i),^([^#].*)$))) hadd $1 $regml(1) $2 elseif ((!$2) && ($regex($read($3-,n,%i),^([^#]\S*)\s+(\d+)$))) hadd $1 $regml(1) $regml(2) dec %i } } alias -l init { hfree -w spamcalc.* hmake spamcalc.tld 10 hmake spamcalc.tail 100 hmake spamcalc.words 100 hmake spamcalc.regex 10 hmake spamcalc.field 10 .echo -q $findfile($datadir,tld*,0,1,add spamcalc.tld 1 $1-) .echo -q $findfile($datadir,whitelist*,0,1,add spamcalc.tail -1 $1-) .echo -q $findfile($datadir,blacklist*,0,1,add spamcalc.tail 0 $1-) .echo -q $findfile($datadir,words*,0,1,add spamcalc.words 0 $1-) .echo -q $findfile($datadir,regexp*,0,1,add spamcalc.regex 0 $1-) .echo -q $findfile($datadir,fields*,0,1,add spamcalc.field 1 $1-) } alias -l tailscore { var %i = 1 while (%i <= $2) { if ($hget(spamcalc.tail,$gettok($1,- $+ %i $+ -,46))) return $ifmatch inc %i } return 0 } alias -l wordscore return $iif($hget(spamcalc.words,$1),$ifmatch,0) alias -l regexscore { var %i = $hget(spamcalc.regex,0).item, %p = 0 while (%i) { if ($regex($1,$hget(spamcalc.regex,%i).item)) %p = $max(%p,$hget(spamcalc.regex,%i).data) dec %i } return %p } alias -l dashesscore { var %i = $numtok($1,45), %s, %v = 0, %m = 0, %t while (%i) { %t = $gettok($1,%i,45) dec %i if ($wordscore(%t)) { inc %v $ifmatch inc %m } elseif ($regexscore(%t)) { inc %v $ifmatch inc %m } } if (%m >= $calc($numtok($1,45) * 0.5)) return $calc(%v * %m) return 0 } alias -l fieldscore { var %i = $hget(spamcalc.field,0).item, %p = 0 while (%i) { if ($regex($1,$hget(spamcalc.field,%i).item)) return 1 dec %i } return 0 } alias -l lookslikeword { var %v = $regex($1,/[aeiouy]/gi), %n = $regex($1,/[0-9]/g) var %c = $calc(($len($1) - %v - %n) / $len($1)) %n = $calc(%n / $len($1)) %v = $calc(%v / $len($1)) return $iif((%c >= $calc(0.75 * %v)) && (%c <= $calc(2.1 * %v)) && !(%n),$true,$false) } alias -l repeatscore { var %i = $hget(spamcalc.repeat,0).item, %repeat = 1 while (%i) { if ($hget(spamcalc.repeat,%i).data > %repeat) %repeat = $ifmatch dec %i } return $calc(40 * (%repeat - 1) ^ 2) } alias -l numfieldscore { if ($1 < 3) return 0 if ($1 <= 6) return $gettok(0 0 5 14 35 68,$1,32) return $calc(15 + ($1 - 1) ^ 3) } alias spamcalc { if (!$0) { if (!$isid) echo $color(info) -aqt * /spamcalc: insufficient parameters return } ; split up name into host and domain part var %n = $numtok($1,46), %d, %h = "" if (%n <= 2) %d = $1 else { %d = $gettok($1,-2-,46) if ($hget(spamcalc.tld,%d)) { %d = $gettok($1,-3-,46) if (%n > 3) %h = $gettok($1,1- $+ $calc(%n - 3),46) } else %h = $gettok($1,1- $+ $calc(%n - 2),46) } var %total = 0, %tail = $tailscore($1,%n) if (%tail >= 0) { hmake spamcalc.repeat 10 var %i = $numtok(%h,46), %num = %i, %t, %ws, %rs, %score = 0, %mult = 0, %apply = 0 var %dashes = 0, %length = 0, %oneletter = 0, %looks = $iif(%i >= 3,$true,$false) while (%i) { %t = $gettok(%h,%i,46) dec %i ; word and regex score %ws = $wordscore(%t) %rs = $regexscore(%t) if ((%ws) || (%rs)) { if ($len(%t) > 2) %apply = 1 if (%ws) inc %score %ws else inc %score %rs inc %mult } ; dashes score if (- isin %t) { if ($regex(%t,/^([a-zA-Z0-9]-)+[a-zA-Z0-9]$/)) inc %dashes 50 else inc %dashes $dashesscore(%t) } ; number of fields score if (($regex(%t,/^[0-9]+$/)) && (%t < 256)) dec %num elseif ($regex(%t,/^[0-9]+-[0-9]+-[0-9]+-[0-9]+$/)) dec %num else dec %num $fieldscore(%t) ; looks-like-word score if ((!%ws) && (%looks) && (!$lookslikeword(%t))) %looks = $false ; repeat score if (%t !isnum) hinc spamcalc.repeat %t ; field length if ($len(%t) > 24) inc %length $ifmatch ; one letter score elseif (($len(%t) == 1) && (%t !isnum)) inc %oneletter } ; final multiplication factor adjustion if ((!%mult) || (!%apply)) %mult = 1 ; final numfields calculation var %fields = $numfieldscore(%num) ; final one-letter calculation if (%oneletter) %oneletter = $calc((%oneletter - 1) * 50) ; final repeat calculation var %repeat = $repeatscore ; final looks-like calculation var %looks = $iif(%looks,$calc(20 * ($numtok(%h,46) - 1)),0) ; final calculation inc %total $calc(%tail + (%mult * %score) + %fields + %length + %repeat + %oneletter + %looks) inc %total $int($calc(0.5 * %dashes)) hfree spamcalc.repeat } if (!$isid) echo $color(info) -aqt * SpamCalc value for $1 $+ : %total return %total }