Bonjour à tous,
Voici un code à partir d'un bout de script de CrazyCat pour récupérer des informations sur une IP via une API : https://forum.eggdrop.fr/Check-de-proxy-...-1874.html
Le script a besoin du package json et http.
Merci à MenzAgitat pour la base du namespace et la désinstallation d'un script sur votre eggdrop : https://forum.eggdrop.fr/Fonction-de-des...-1430.html
Pour revenir au script, je suis resté le plus simpliste possible pour une bonne compréhension de l'algorithme.
La commande est en message privé, c'est à dire /msg Bot infoip <IP>
Ce script est évolutif , vous pouvez en faire ce que vous voulez.
Voici un code à partir d'un bout de script de CrazyCat pour récupérer des informations sur une IP via une API : https://forum.eggdrop.fr/Check-de-proxy-...-1874.html
Le script a besoin du package json et http.
Merci à MenzAgitat pour la base du namespace et la désinstallation d'un script sur votre eggdrop : https://forum.eggdrop.fr/Fonction-de-des...-1430.html
Pour revenir au script, je suis resté le plus simpliste possible pour une bonne compréhension de l'algorithme.
La commande est en message privé, c'est à dire /msg Bot infoip <IP>
tcl
## Proxycheck.tcl
## Version: v1.0
if {[::tcl::info::commands ::proxycheck::uninstall] eq "::proxycheck::uninstall"} { ::proxycheck::uninstall }
if { [package vcompare [regexp -inline {^[[:digit:]\.]+} $::version] 1.6.20] == -1 } {
putloglev o * "\00304\[proxycheck - erreur\]\003 La version de votre Eggdrop est\00304 ${::version}\003; Proxycheck ne fonctionnera correctement que sur les Eggdrops version 1.6.20 ou supérieure." ; return }
if { [::tcl::info::tclversion] < 8.5 } {
putloglev o * "\00304\[proxycheck - erreur\]\003 Proxycheck nécessite que Tcl 8.5 (ou plus) soit installé pour fonctionner. Votre version actuelle de Tcl est\00304 ${::tcl_version}\003." ; return }
package require Tcl 8.5
package require http
package require json
namespace eval ::proxycheck {
# Procédure de désinstallation : le script se désinstalle totalement avant
# chaque rehash ou à chaque relecture au moyen de la commande "source" ou
# autre.
proc ::proxycheck::uninstall {args} {
putlog "Désallocation des ressources de \002proxycheck.tcl\002..."
# Suppression des binds.
foreach binding [lsearch -inline -all -regexp [binds *[set ns [::tcl::string::range [namespace current] 2 end]]*] " \{?(::)?$ns"] {
unbind [lindex $binding 0] [lindex $binding 1] [lindex $binding 2] [lindex $binding 4]
}
namespace delete ::proxycheck
}
}
proc ::proxycheck::ipcheck {nick uhost handle text} {
if {$text eq ""} {
puthelp "NOTICE $nick :Syntaxe: infoip <ip>";
return
}
# Encoding pour corriger un problème de charset. Ex: Ãle-de-France
set data [encoding convertfrom utf-8 [::proxycheck::getipdatas $text]]
if {[llength $data] == 0 || ([dict exists $data status] && [dict get $data status] ne "success")} {
puthelp "NOTICE $nick :Aucune donnée pour $text."
return 0
}
if {[dict get $data status] eq "success"} {
set country [dict get $data country]
set region [dict get $data regionName]
set city [dict get $data city]
set codepays [dict get $data countryCode]
set codepostal [dict get $data zip]
set isp [dict get $data isp]
set mobile [dict get $data mobile]
set proxy [dict get $data proxy]
set hosting [dict get $data hosting]
puthelp "NOTICE $nick :Pays: $country ($codepays) - Région: $region - Ville: $city ($codepostal)"
puthelp "NOTICE $nick :FAI: $isp - Proxy: $proxy - Mobile: $mobile - Hébergeur: $hosting"
}
}
proc ::proxycheck::json2dict {JSONtext} {
string range [string trim [string trimleft [string map {\t {} \n {} \r {} , { } : { } \[ \{ \] \}} $JSONtext] {\uFEFF}]] 1 end-1
}
proc ::proxycheck::getipdatas { ip } {
::http::config -useragent "lynx"
set ipq [http::geturl http://ip-api.com/json/$ip?fields=mobile,country,regionName,countryCode,city,zip,isp,hosting,status,proxy,query&lang=fr]
set data [json2dict [http::data $ipq]]
::http::cleanup $ipq
return $data
}
bind msg - "infoip" ::proxycheck::ipcheck
bind evnt - prerehash ::proxycheck::uninstall
putlog "Proxycheck.tcl v1.0 chargé."
Ce script est évolutif , vous pouvez en faire ce que vous voulez.