#--------------------------------------------------------------------- # maskhost.tcl # Tcl script for irc bot eggdrop # # Some networks encrypt/obscure the hostnames and ips. # This script redefines the [maskhost] procedure # # Examples: # n!u@foo.com -> *!u@foo.com # n!u@foo.bar.com -> *!n@*.bar.com # n!u@foo.users.undernet.org -> *!*@foo.users.undernet.org # n!u@6XcSdq.G242ff.com -> *!u@*.G242ff.com (encrypted hostname) # n!u@6rRQ.Trqu.BGA41ff -> *!u@6rRQ.Trqu.* (encrypted ip) # # v0: 25-Jan-2003 # v1: 25-Jan-2003 # v2: 26-Jan-2003 # v3: 14-Oct-2003 #--------------------------------------------------------------------- package require eggdrop 1.6.13 package require Tcl 8.0 #--------------------------------------------------------------------- # test maskhost #--------------------------------------------------------------------- bind pub m !maskhost pub:maskhost proc pub:maskhost { nick uhost hand chan text } { puthelp "PRIVMSG $chan :$text -> [maskhost $text]" } #--------------------------------------------------------------------- # new maskhost procedure #--------------------------------------------------------------------- proc maskhost { nuhost } { global strict-host # scan out nick, user and host set scanrule {%[^!]!%[^@]@%s} if { [scan $nuhost $scanrule nick user host] != 3 } { # unable to scan out the host. return $nuhost } # in case the variable "strict-host" is set to 0, a leading "~" # is stripped off by eggdrop. The default maskhost proc will # replace the "~" by a "*". Or, in case strict-host is set to # 1, the "~" is replaced by a "?". This proc does that too. if { ![info exists ${strict-host} ] } { set shost 0 } else { set shost ${strict-host} } if { $shost == 0 } { regsub {~} $user {*} user } else { regsub {~} $user {?} user } # split the hostname and determine length set hostlist [split $host "."] set lenglist [llength $hostlist] # is the nuhost like n!u@foo.com ? if { $lenglist == 2 } { set mask "*!$user@$host" return $mask } # another network: undernet set undermask "*.users.undernet.org" if { [string match -nocase $undermask $host] } { set mask "*!*@$host" return $mask } # is it an encrypted ip or a partially encrypted hostname? # the only clues (?): the top level domain ending or a number # in the top level domain ending indicating an encrypted ip. # define a list of hostendings which are considered tlds. lappend tlds com net org info biz de ca us mx etc.. what a mess lappend tlds nu ru se de no fi ee ch fr es pt be lu bg ro jp my lappend tlds id br bn ar th kr cn au nz nl # review host ending set hostend [lindex $hostlist end] set hostend [string tolower $hostend] # review based on tld ... # if { [lsearch $tlds $hostend] == -1 } { } # ... or review based on numbers in the hostend if {[string match {*[0-9]*} $hostend]} { # an encrypted ip set mask [lrange $hostlist 0 [expr $lenglist - 2]] set mask [join $mask "."] set mask "*!$user@$mask.*" return $mask } else { # an encrypted hostname set mask [lrange $hostlist 1 end] set mask [join $mask "."] set mask "*!$user@*.$mask" return $mask } } putlog {Redefinition of [maskhost] version 2 loaded.}