Voici un petit code rapide, fait avec les divers éléments de cette discussion et d'autres du forum:
Ce n'est pas testé mais il ne devrait pas y avoir de gros bug dedans
tcl
set ipfile "myips.txt"
set ips {}
bind pub - .ipadd ipadd
bind pub - .ipdel ipdel
bind raw - NOTICE proxy:connect
set mask {^(?:25[0-5]|2[0-4]\d|[0-1]?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|[0-1]?\d{1,2})){3}$}
proc proxy:connect {from keyword text} {
if {[string match -nocase "*Client connecting*" $text]} {
regexp {\:\ (.*)\ \((.*?)@(.*?)\)} $text matching nick username ip
if {[lsearch $::ips $ip] != -1} {
putserv "PRIVMSG #opers :Pas de test pour $ip : dans la base d'exemption"
return
}
set data [getipdatas $ip]
set Getquery [dict get $data query]
set Getcountry [dict get $data country]
set GetcountryCode [dict get $data countryCode]
set Getcity [dict get $data city]
set Getisp [dict get $data isp]
set Getas [dict get $data as]
set Getreverse [dict get $data reverse]
if {[dict get $data status] eq "success"} {
if {[dict get $data proxy] eq "true"} {
putserv "PRIVMSG #opers :\00304Gline Proxy/Vpn\003 $ip ($Getcity $Getcountry)"
putquick "GLINE *@$ip +1d :Proxy/VPN $Getcountry"
}
}
}
}
proc ipadd {nick uhost handle chan text} {
if {![regexp $::mask $text ipv4]} {
putserv "PRIVMSG $nick :$text n'est pas une IP valide"
return
}
if {[lsearch $::ips $text]==-1} {
lappend ::ips $text
}
writeip
}
proc ipdel {nick uhost handle chan text} {
if {[lsearch $::ips $text]!=-1} {
lreplace ::ips [lsearch $::ips $text] [lsearch $::ips $text]
}
writeip
}
proc writeip {} {
set fo [open $::ipfile w]
puts $fo [join $::ips "\n"]
close $fo
}
proc readip {} {
set fi [open $::ipfile r]
set ::ips [split [read -nonewline $fi] "\n"]
close $fi
}
proc json2dict {JSONtext} {
string range [string trim [string trimleft [string map {\t {} \n {} \r {} , { } : { } \[ \{ \] \}} $JSONtext] {\uFEFF}]] 1 end-1
}
proc getipdatas { ip } {
::http::config -useragent "lynx"
set ipq [http::geturl http://ip-api.com/json/$ip?fields=status,message,continent,country,countryCode,region,regionName,city,zip,lat,lon,timezone,currency,isp,org,as,reverse,mobile,proxy,hosting,query&lang=en]
set data [json2dict [http::data $ipq]]
::http::cleanup $ipq
return $data
}
readip
Ce n'est pas testé mais il ne devrait pas y avoir de gros bug dedans