## Download latest csv db from http://ip-to-country.directi.com/ ## Atau dari http://channels.dal.net/fraud/ipchk.tgz ######################## EDIT TO YOUR PREF ############################## set ip2c(trigger) "`ip" set ip2c(flag) "-" set ip2c(chan) "" set ip2c(database) "scripts/ipchk.csv" set ip2c(sql) "0" set ip2c(type) 0 set ip2c(bold) 1 set ip2c(mode) 0 set ip2c(switch) 1 ############################### DO NOT EDIT BELOW ############################## set ip2c(vrs) "free" set ip2c(tag) "1088746257" # BINDS bind pub $ip2c(flag) $ip2c(trigger) ip2c:pub bind raw - 302 raw:302 bind evnt - init-server conn:init # PROCS # Bold switch if {[info exists ip2c(bold)]} { switch -- $ip2c(bold) { "0" { set ip2c(boldset) "" } "1" { set ip2c(boldset) "\002" } } } else { putlog "Ip-to-Country could contain errors, a required variable couldn't be resolved." return 0 } if {![info exists ip2c(boldset)]} { putlog "Ip-to-Country could contain errors, a required variable couldn't be resolved." return 0 } # Msg type switch if {[info exists ip2c(type)]} { switch -- $ip2c(type) { "0" { set ip2c(putserv) "PRIVMSG %CHAN%" } "1" { set ip2c(putserv) "PRIVMSG %NICK%" } "2" { set ip2c(putserv) "NOTICE %NICK%" } } } else { putlog "Ip-to-Country could contain errors, a required variable couldn't be resolved." return 0 } if {![info exists ip2c(bold)]} { putlog "Ip-to-Country could contain errors, a required variable couldn't be resolved." return 0 } # Main public proc (channel commands) proc ip2c:pub {nick host hand chan arg} { global ip2c set arg [string map {\\ \\\\ \[ \\\[ \] \\\] \{ \\\{ \} \\\} \" \\\"} $arg] if {([string match -nocase *$ip2c(chan)* $chan] || [string match -nocase {} $chan]) && [isstatus $nick $chan]} { if {[string match -nocase {} [lindex $arg 0]]} { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :Invalid option, $ip2c(boldset)$ip2c(trigger) -help$ip2c(boldset) for a list of options." } elseif {![string match -nocase {} [lindex $arg 1]] && ![string match -nocase "-set" [lindex $arg 0]] && ![string match -nocase "-ban" [lindex $arg 0]] && ![string match -nocase "-longip" [lindex $arg 0]] && ![string match -nocase "-ipaddr" [lindex $arg 0]]} { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :Error to mutch variables, usage: $ip2c(trigger) ." } elseif {[isipaddr [lindex $arg 0]] && $ip2c(switch)} { set output [ip2country [lindex $arg 0]] set result(0) "[lindex $output 0]" set result(1) "[lindex $output 1]" set result(2) "[join [lrange $output 2 end]]" if {$result(0) != "00"} { foreach line [split $result(2) \x20] { if {[info exists word]} { append word \x20[word_format $line] } else { set word [word_format $line] } } putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :\[4IPCheck!\] [lindex $arg 0] 3This IP From 7[join [lrange $word 0 end]] 3\[7$result(0)3\]" } else { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :$result(2)" } } elseif {[ishost [lindex $arg 0]] && $ip2c(switch)} { dnslookup "[string map {\\ \\\\ \[ \\\[ \] \\\] \{ \\\{ \} \\\} \" \\\"} [lindex $arg 0]]" resolve:ipaddrhost "[string map {\\ \\\\ \[ \\\[ \] \\\] \{ \\\{ \} \\\} \" \\\"} $nick]" "[string map {\\ \\\\ \[ \\\[ \] \\\] \{ \\\{ \} \\\} \" \\\"} $chan]" } elseif {[string match -nocase "-about" [lindex $arg 0]]} { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :IP to Country TCL by primo" } elseif {[string match -nocase "-update" [lindex $arg 0]] && [matchattr $nick m]} { set vrschk [newupdates] if {[string match -nocase "-1" $vrschk]} { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :Error gak bisa konek ke server." } else { if {$vrschk} { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :You are using the latest version." } else { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :You are not using the latest version check http://www.primo.ma.cx for updates." } } } elseif {[string match -nocase "-help" [lindex $arg 0]]} { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :IP to Country TCL command list." putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :$ip2c(trigger) ::: perfrom lookup." putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :$ip2c(trigger) -ban ::: only for ops bans all users that match the country." putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :$ip2c(trigger) -set ::: only for ops turns trigger status on or off." putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :$ip2c(trigger) -status ::: only for ops shows current script status." putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :$ip2c(trigger) -update ::: checks if your using the latest script version." putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :$ip2c(trigger) -about ::: shows info about this script." } elseif {[string match -nocase "-ban" [lindex $arg 0]] && [matchattr $nick o]} { if {![string match -nocase {} [lindex $arg 1]] && [string match -nocase {} [lindex $arg 2]]} { if {([string bytelength [lindex $arg 1]] == 2) && [regexp -all {[a-zA-Z]} [lindex $arg 1]]} { bancountry [lindex $arg 1] $chan } else { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :Invalid country code." } } else { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :Usage: $ip2c(trigger) -ban <2digit country code>." } } elseif {[string match -nocase "-longip" [lindex $arg 0]]} { if {[isipaddr [lindex $arg 1]] && ![string match -nocase {} [lindex $arg 1]] && [string match -nocase {} [lindex $arg 2]]} { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :LongIP for \($ip2c(boldset)[lindex $arg 1]$ip2c(boldset)\) is \($ip2c(boldset)[ip2longip [lindex $arg 1]]$ip2c(boldset)\)" } elseif {[string match -nocase {} [lindex $arg 1]] || ![string match -nocase {} [lindex $arg 2]]} { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :Usage: $ip2c(trigger) -longip " } else { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :\($ip2c(boldset)[lindex $arg 1]$ip2c(boldset)\) is not a valid ipaddr." } } elseif {[string match -nocase "-ipaddr" [lindex $arg 0]]} { if {[regexp -all {[0-9]} [lindex $arg 1]] && ![string match -nocase {} [lindex $arg 1]] && [string match -nocase {} [lindex $arg 2]]} { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :IpAddr for \($ip2c(boldset)[lindex $arg 1]$ip2c(boldset)\) is \($ip2c(boldset)[longip2ip [lindex $arg 1]]$ip2c(boldset)\)" } elseif {[string match -nocase {} [lindex $arg 1]] || ![string match -nocase {} [lindex $arg 2]]} { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :Usage: $ip2c(trigger) -ipaddr " } else { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :\($ip2c(boldset)[lindex $arg 1]$ip2c(boldset)\) is not a valid longip." } } elseif {[string match -nocase "-status" [lindex $arg 0]] && [matchattr $nick m]} { if {$ip2c(switch)} { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :Trigger status is turned \($ip2c(boldset)on$ip2c(boldset)\)." } else { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :Trigger status is turned \($ip2c(boldset)off$ip2c(boldset)\)." } } elseif {[string match -nocase "-set" [lindex $arg 0]] && [matchattr $nick m]} { if {[string equal -nocase {} [lindex $arg 1]]} { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] ::Usage: $ip2c(trigger) -set ." } else { if {[string equal -nocase "on" [lindex $arg 1]]} { if {!($ip2c(switch))} { set ip2c(switch) 1 putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :Turned trigger status \($ip2c(boldset)on$ip2c(boldset)\)." } else { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :Allready turned on." } } elseif {[string equal -nocase "off" [lindex $arg 1]]} { if {$ip2c(switch)} { set ip2c(switch) 0 putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :Turned trigger status \($ip2c(boldset)off$ip2c(boldset)\)." } else { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :Allready turned off." } } else { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] ::Usage: $ip2c(trigger) -set ." } } } else { if {[onchan [lindex $arg 0] $chan] && $ip2c(switch)} { dnslookup [lindex [split [getchanhost [lindex $arg 0]] \x40] 1] resolve:ipaddrnick [string map {\\ \\\\ \[ \\\[ \] \\\] \{ \\\{ \} \\\} \" \\\"} [lindex $arg 0]] [string map {\\ \\\\ \[ \\\[ \] \\\] \{ \\\{ \} \\\} \" \\\"} $chan] } elseif {$ip2c(switch)} { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :\($ip2c(boldset)[lindex $arg 0]$ip2c(boldset)\) is not on the current channel." } } } } # Resolve ipaddr with nick identifyer proc resolve:ipaddrnick {ipaddr hostname status nick chan} { global ip2c if {[ip2longip $ipaddr]} { if {[isipaddr $ipaddr]} { set output [ip2country $ipaddr] set result(0) "[lindex $output 0]" set result(1) "[lindex $output 1]" set result(2) "[join [lrange $output 2 end]]" if {$result(0) != "00"} { foreach line [split $result(2) \x20] { if {[info exists word]} { append word \x20[word_format $line] } else { set word [word_format $line] } } putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :\[4IPCheck!\] 3IP Nick $nick 3is from 7[join [lrange $word 0 end]] 3\[7$result(0)3\]" } else { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :$result(2)" } } } else { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :\[4IPCheck!\] There is 4No IP 3\[7$hostname3\] For 3\[7$nick3\]" } } # resolve ipaddr from host proc resolve:ipaddrhost {ipaddr hostname status nick chan} { global ip2c if {[ip2longip $ipaddr]} { if {[isipaddr $ipaddr]} { set output [ip2country $ipaddr] set result(0) "[lindex $output 0]" set result(1) "[lindex $output 1]" set result(2) "[join [lrange $output 2 end]]" if {$result(0) != "00"} { foreach line [split $result(2) \x20] { if {[info exists word]} { append word \x20[word_format $line] } else { set word [word_format $line] } } putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :\[4IPCheck!\] $hostname 3This IP From 7[join [lrange $word 0 end]] 3\[7$result(0)3\]" } else { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :$result(2)" } } } else { putserv "[string map [list %CHAN% $chan %NICK% $nick] $ip2c(putserv)] :\[4IPCheck!\] There is 4No IP 3\[7$hostname3\]" } } # Reverse a string proc reverse_string {arg} { set out {} foreach line [split $arg {}] {set out $line$out} set out } # Create a long ip out of a numeric ip proc ip2longip {ipaddr} { foreach ipbyte [split $ipaddr \x2E] { append hexaddr [format {%02x} $ipbyte] } return [format {%u} "0x$hexaddr"] } # Create a normal numeric ip from longip proc longip2ip {longip} { return [expr {$longip>>24&255}]\x2E[expr {$longip>>16&255}]\x2E[expr {$longip>>8&255}]\x2E[expr {$longip&255}] } # Check if the ipaddr is nummeric proc isipaddr {ipaddr} { if {[string match -nocase {} $ipaddr]} { return 0 } foreach line [split $ipaddr \x2E] { if {![regexp ^\[0-9\]+$ $line]} { return 0 } elseif {$line > 255} { return 0 } if {[info exists count]} { incr count } else { set count 1 } } if {$count != 4} { return 0 } else { return 1 } } # Checking if ipaddr is a real internet ipaddr and not a lan ip or localhost.. proc isvalidip {ipaddr} { if {(([ip2longip $ipaddr] >= 2130706432) && ([ip2longip $ipaddr] <= 2130706687)) || (([ip2longip $ipaddr] >= 167772160) && ([ip2longip $ipaddr] <= 184549375)) || (([ip2longip $ipaddr] >= 2886729728) && ([ip2longip $ipaddr] <= 2887778303)) || (([ip2longip $ipaddr] >= 3232235520) && ([ip2longip $ipaddr] <= 3232301055)) || (([ip2longip $ipaddr] >= 2851995648) && ([ip2longip $ipaddr] <= 2852061183)) || (([ip2longip $ipaddr] >= 3758096384) && ([ip2longip $ipaddr] <= 4026531839))} { return 0 } else { return 1 } } # Basicly this checks if the input is # a host, and if this host is valid # by checking if there are "." within # the string and by checking if the tld # is not a number. proc ishost {host} { foreach {a b} [split [reverse_string $host] \x2E] break if {[regexp -all {[a-zA-Z]} $a] && [regexp -all {[a-zA-Z0-9]} $b]} { if {![string match -nocase {} $a] && ![string match -nocase {} $b]} { return 1 } else { return 0 } } else { return 0 } } # Reformat string every word will be set # to lower then only the first char will # be to upper. proc word_format {arg} { foreach line [split [string tolower $arg] {}] { if {[info exists word]} { append word $line } else { set word [string toupper $line] } } return $word } # This will lookup the country codes proc ip2country {ipaddr} { global ip2c mysql if {![info exists mysql(conn)] && $ip2c(sql)} { set mysql(conn) [mysqlconnect -host $mysql(host) -port $mysql(port) -user $mysql(user) -password $mysql(pass)] } if {[isvalidip $ipaddr]} { if {$ip2c(sql)} { if {[ip2longip $ipaddr]} { mysqluse $mysql(conn) $mysql(data) foreach query [mysqlsel $mysql(conn) "SELECT resolve_start,resolve_end,resolve_code_2,resolve_code_3,resolve_fullname FROM resolve WHERE ([ip2longip $ipaddr] >= resolve_start) and ([ip2longip $ipaddr] <= resolve_end);" -list] { if {![info exists test]} { set location(0) "[lindex $query 2]" set location(1) "[lindex $query 3]" set location(2) "[join [lrange $query 4 end]]" } else { putlog "Error to many results." } } } if {[array exists location]} { if {[string match -nocase {} $location(0)]} { set location(0) "00" } if {[string match -nocase {} $location(1)]} { set location(1) "000" } if {[string match -nocase {} $location(2)]} { set location(2) "Unknown" } return "$location(0) $location(1) $location(2)" } else { return "00 000 Maap, 3\[7$ipaddr3\]4 Tidak Terdaftar dalam database." } } else { if {[file exists $ip2c(database)]} { if {[ip2longip $ipaddr]} { set rfile [open "$ip2c(database)" r] while {![eof $rfile]} { gets $rfile line set data [string map {\x22 {} \x2C \x20} $line] if {[ip2longip $ipaddr] >= [lindex $data 0]} { if {[ip2longip $ipaddr] <= [lindex $data 1]} { set location(0) [lindex $data 2] set location(1) [lindex $data 3] set location(2) [join [lrange $data 4 end]] break } } } close $rfile if {[array exists location]} { return "$location(0) $location(1) $location(2)" } else { return "00 000 Maap, 3\[7$ipaddr3\]4 Tidak Terdaftar dalam database." } } } else { putlog "Can't find the cvs database." } } } else { return "00 000 iTUkaN Ip Localhost 4gObLoK!" } } # Channel mode support is .. v/h/o proc isstatus {nick chan} { global ip2c if {$ip2c(mode)} { if {[isvoice $nick $chan] && ($ip2c(mode) == 1)} { return 1 } elseif {[ishalfop $nick $chan] && ($ip2c(mode) <= 2)} { return 1 } elseif {[isop $nick $chan] && ($ip2c(mode) <= 3)} { return 1 } else { return 0 } } else { return 1 } } # Will catch the host from irc this will # give you a real ip and resolve it proc raw:302 {from key arg} { global botnick if {[string match -nocase [lindex [split [lindex [split [join [lrange $arg 0 end]] \x3D] 0] \x3A] 1] $botnick]} { dnslookup "[lindex [split [join [lrange $arg 0 end]] \x40] 1]" resolve:raw } } # resolving the bots host proc resolve:raw {ipaddr hostname status} { global MyIP set MyIP "$ipaddr" } # A command that returns $MyIP variable # this is usefull when users have that # have a nat ip and wich to resolve the # bots ip or for users with huge amount # of ips for example if you are on a # shell provider and you don't bind your # bot to a certain ip this will resolve # it for you each time the bot connects. proc MyIP {} { global MyIP if {[info exists MyIP]} { if {[string match {} $MyIP] || [ip2longip $MyIP] || [isvalidip $MyIP]} { set MyIP {} foreach a {a b c d e f g h i j k} { catch { set external [socket $a.root-servers.net 53] set MyIP [lindex [fconfigure $external -sockname] 0] close $external } if { ![string equal $MyIP {}] } { break } } return $MyIP } else { return $MyIP } } else { set MyIP {} foreach a {a b c d e f g h i j k} { catch { set external [socket $a.root-servers.net 53] set MyIP [lindex [fconfigure $external -sockname] 0] close $external } if { ![string equal $MyIP {}] } { break } } return $MyIP } } # Perfrom on connect proc conn:init init-server { global botnick putserv "USERHOST $botnick" } # Returns country code 2 digits proc location:type0 {} { set location [lindex [ip2country [MyIP]] 0] if {[regexp -all {[0-9]} $location]} { set location "Unknown" } return $location } # Returns country code 3 digits proc location:type1 {} { set location [lindex [ip2country [MyIP]] 1] if {[regexp -all {[0-9]} $location]} { set location "Unknown" } return $location } # Returns full country name proc location:type2 {} { foreach line [split [join [lrange [ip2country [MyIP]]] 2 end] \x20] { if {[info exists location]} { append location \x20[word_format $line] } else { set location [word_format $line] } } if {[regexp -all {[0-9]} [lindex [ip2country [MyIP]] 0]]} { set location "Unknown" } return $location } putlog "=== EchiEgg IPCheck to Country TCL Loaded"