[Kroc] - 24 Sep 2004 - This is basic GeoIP (see http://www.maxmind.com for details) that return country code for a given IP adress. ################################################################################ # # Basic GeoIP for tcl. # # Copyright © 2004 - David Zolli - http://www.kroc.tk # # This script is under NOL : http://wiki.tcl.tk/nol # # Version 1.0 - 24 Sep 2004 # ################################################################################ # This needs Maxmind CVS database available here : # http://www.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip proc GeoIP { IP {cvsfile GeoIPCountryWhois.csv} } { foreach "a b c d" [split $IP .] { set Value [join "[expr 1000 + $a] [expr 1000 + $b] [expr 1000 + $c] [expr 1000 + $d]" {}] } set fin [open $cvsfile r] while {![eof $fin]} { foreach "1 2 3 4 5 6" [split [gets $fin] ,] { # compute numbers from IP adresses : foreach "a b c d" [split [lindex $1 0] .] { set min [join "[expr 1000 + $a] [expr 1000 + $b] [expr 1000 + $c] [expr 1000 + $d]" {}] } foreach "a b c d" [split [lindex $2 0] .] { set max [join "[expr 1000 + $a] [expr 1000 + $b] [expr 1000 + $c] [expr 1000 + $d]" {}] } if { $Value >= $min && $Value <= $max } { close $fin return [string tolower [lindex $5 0]] } } } close $fin return unknow }