Hai sa fim practici!
RSS icon Email icon Home icon
  • Public IP Info v 0.2 - script TCL pentru eggdrop

    Posted on March 31st, 2009 admin No comments

    Acest script il puteti folosi pentru eggdrop pentru a va afisa, pe canalul IRC unde a fost declansata comanda, informatii despre un anumit IP.

    Foloseste ca sursa de informatii www.ip2location.com, iar informatiile solicitate le stocheaza intro “baza de date” proprie pentru a reduce solicitarea serverului unde este gazduit botul.

    De mentionat este faptul ca informatiile stocate sunt retinute pentru a o anumita perioada de timp (se poate seta in configuratia scriptului). In acest fel datale nu se vor invechi.

    Scriptul in actiune:

    [13:27] <hwk> !ipinfo 92.81.168.244
    [13:27] <Myth`> hwk IP information for 92.81.168.244: Country: ROMANIA, City: BACAU, ISP: ROMTELECOM DATA NETWORK, Domain: PLATINUM-IFN.RO

    Versiunea 0.1 a acestui script se poate descarca de pe www.egghelp.org, sectiunea TCL Archive, sub numele: Public IP information checker.

    Diferentele intre cele doua versiuni fiind sistemul de stocare temporara a datelor.

    catch {array unset ipinfocache}
    #########################################################################
    #         Public IP Info v0.2 by Hawkee - lowraider1@gmail.com          #
    #-----------------------------------------------------------------------#
    # This script uses www.ip2location.com to check info for an ip adresses #
    #	You can use it in 2 modes: THE FREE ONE or THE Account one	  #
    #										  #
    # The free one works for 20 IP lookups per day, because this is the 	  #
    # maximum number of lookups, ip2location.com offers for unregistered 	  #
    # users - per ip -. Set ip2loc(account) (default) to use this.		  #
    #									         #
    # Changes from version 0.1:							  #
    #		-implemented a cache system to store the info to reduce	  #
    #		resource usage                                            #
    #             -the cache system refreshes the info at a given period of #
    #		time                                                      #
    #										  #
    #										  #
    # Works on all channels, and it can be used by all users. Requires TCL  #
    # HTTP PACK									  #
    #										  #
    # USAGE: !ipinfo <IP>							  #
    # 					HAVE PHUN				  #
    # Email me with suggestions and bug reports at lowraider1@gmail.com 	  #
    #										  #
    #							 grtz HWK @ undernet	  #
    #########################################################################
    
    set ipinfo(cachefile) 	"ipinfo.cache"		;#the cache file
    set ipinfo(cacherefresh) 	"7"					;#the time (in days) to refresh the info for an IP
    
    set ver "0.2 - mod"
    
    package require http
    
    #DO NOT EDIT BELOW FUCKER!#
    
    proc ipinfo:parser {nick uhost hand chan args} {
    
    set ip [string trimright [lindex $args 0] "."]
    
    if {![regexp {^(?:(?:[01]?\d?\d|2[0-4]\d|25[0-5])(\.|$)){4}$} $ip]} {
    puthelp "privmsg $chan :$nick NO/Invalid IP pattern. USAGE: !ipinfo 193.193.193.193"
    putlog "IP INFO $chan $nick - INVALID IP PATTERN"
    return
    
    }
    
    set infoip [ipinfo:output $ip]
    set country [lindex $infoip 0]
    set city [lindex $infoip 1]
    set isp [lindex $infoip 2]
    set domain [lindex $infoip 3]
    
    if {![info exists country] || [string equal $country -]} {
    puthelp "privmsg $chan :$nick No information found for IP: \00302$ip\003 please redefine your IP"
    putlog "IP INFO $chan $nick - No results"
    return
    }
    
    puthelp "privmsg $chan :$nick IP information for \00302$ip\003: \002Country:\002 \00304$country\003, \002City:\002 \00304$city\003, \002ISP\002: \00302$isp\003, \002Domain:\002 \00302$domain\003"
    putlog "IPinfo request:  $nick on $chan"
    
    }
    
    proc ipinfo:getinfo {host} {
    global ipinfo ipinfocache
    
    	::http::config -useragent "Mozilla/5.0 ; Gecko"
    
    	set que [::http::formatQuery ipaddresses $host]
       	set http_req [::http::geturl "http://www.ip2location.com/demo.aspx" -timeout 2000 -query $que]
    
    	set data [::http::data $http_req]
    	::http::cleanup $http_req
    
    	regexp {<span id="dgLookup__ctl2_lblICountry">([^<]+)</span></TD>} $data -> country
    	regexp {<span id="dgLookup__ctl2_lblICity">([^<]+)</span></TD>} $data -> city
    	regexp {<span id="dgLookup__ctl2_lblIISP">([^<]+)</span></TD>} $data -> isp
    	regexp {<span id="dgLookup__ctl2_lblIDomain">([^<]+)</span></TD>} $data -> domain
    
    	set info[list $country $city $isp $domain [unixtime]]
    
    	set ipinfocache($host) $info
    
    	return $info
    
    }
    
    proc ipinfo:output {host} {
    global ipinfo ipinfocache
    
    if {[info exists ipinfocache($host)]} {
    	if {[expr {(60*60*24)*$ipinfo(cacherefresh)}] < [expr {[unixtime] - [lindex $ipinfocache($host) 4]}]} {
    		putlog "IPinfo: refreshing cache data for $host"
    		set info [ipinfo:getinfo $host]
    		ipinfo:save
    		return $info
    	} else {
    	return $ipinfocache($host)
    	}
    } else {
    	set info [ipinfo:getinfo $host]
    	ipinfo:save
    	return $info
    }
    
    }
    
    proc ipinfo:save {} {
    global ipinfo ipinfocache
    
    set write [open $ipinfo(cachefile) w]
    puts $write	[list array set ipinfocache [array get ipinfocache]]
    close $write
    
    }
    
    proc ipinfo:read {} {
    global ipinfo ipinfocache
    
    if {[file exists $ipinfo(cachefile)]} {
    	if {![catch {source $ipinfo(cachefile)} cacheerror]} {
    		putlog "IPinfo: cache file successfully loaded"
    	} else {
    		putlog "IPinfo: cache file failed to load -: $cacheerror"
    		putlog "IPinfo: trying to fix cache file: reset" ; ipinfo:save
    
    	}
    } else {
    
    ipinfo:save
    putlog "IPinfo: cache file written - first time use"
    }
    
    }
    
    ipinfo:read
    
    bind pub -|- !ipinfo ipinfo:parser
    
    putlog "Public IP Info $ver by HAWKEE Successfuly loaded"

    Leave a reply

    Security Code: