| View previous topic :: View next topic |
| Author |
Message |
holycrap Op
Joined: 21 Jan 2008 Posts: 152
|
Posted: Mon Apr 20, 2009 10:55 am Post subject: Public IP Information Checker [SOLVED] |
|
|
Hi,
I tried emailing the author of this script, but no luck. Can someone please modify the following script to pull the data from "http://www.ip-adress.com/ip_tracer/" instead of "www.ip2location.com". I find that ip2location do not have very accurate information.
Thanks!
| Code: |
#########################################################################
# Public IP Information Checker by Hawkee - lowraider1@gmail.com #
#-----------------------------------------------------------------------#
# This script uses www.ip2location.com to check for info on ip adresses #
# i'm not quite sure if the login method i made work 100 %, but it #
# seemd to work for me. I have spotted a bug by now, i will review it #
# in a future version. #
# 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. #
# #
# The Account one works for 200 lookups per day if you have a #
# ip2location.com account. The login method for this mode is not #
# guaranteed to work. But you can try. You must set ip2loc(account) to #
# 1 and you must set ip2loc(mail) & ip2loc(pass) with your ip2location #
# account details. #
# Thats all about the important info. #
# #
# Works on all channels, and it can be used by all users. Requires TCL #
# HTTP PACK #
# #
# USAGE: !whereis <IP> #
# HAVE PHUN #
# Email me with suggestions and bug reports #
# #
# grtz HWK @ undernet #
#########################################################################
bind pub -|- !whereis whereis
set ver "0.1"
set ip2loc(account) "0"
set ip2loc(mail) "your ip2location.com account email adress"
set ip2loc(pass) "your ip2location.com account password"
package require http
# DO NOT EDIT BELOW #
proc whereis {nick uhost hand chan args} {
global ip2loc
set ip [lindex $args 0]
::http::config -useragent "Mozilla/5.0 ; Gecko"
if {![info exists authed] && $ip2loc(account) == "1"} {
set auth [::http::formatQuery txtEmailAddress $ip2loc(mail) txtPassword $ip2loc(pass) chkRememberMe on]
::http::geturl "http://www.ip2location.com/login.aspx" -timeout 2000 -query $auth -type mime-type
puthelp "privmsg $chan :Authentificating to website"
set authed "1"
putlog "IP INFO - Logging in to website"
}
if {![string match -nocase *.*.*.* $ip]} {puthelp "NOTICE $nick Invalid IP pattern. \037Syntax\037: \002!whereis\002 <xxx.xxx.xxx.xxx>" ; putlog "IP INFO $chan $nick - INVALID IP PATTERN"; return 0}
set que [::http::formatQuery ipaddresses $ip]
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 x country
if {![info exists country] || [string equal $country -]} {puthelp "NOTICE $nick :$nick, no information found for IP: \00302$ip\003" ; putlog "IP INFO $chan $nick - No results" ; return 0}
regexp {<span id="dgLookup__ctl2_lblICity">([^<]+)</span></TD>} $data x city
regexp {<span id="dgLookup__ctl2_lblIISP">([^<]+)</span></TD>} $data x isp
regexp {<span id="dgLookup__ctl2_lblIDomain">([^<]+)</span></TD>} $data x domain
puthelp "privmsg $chan \037Location\037 - \002Country:\002 \00304$country\003, \002City:\002 \00304$city\003"
putlog "IP INFO $chan $nick"
}
putlog "*Ip Information v$ver* Loaded" |
Last edited by holycrap on Sat Nov 28, 2009 5:33 am; edited 9 times in total |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Wed Apr 22, 2009 8:17 pm Post subject: |
|
|
| Quote: | <speechles> !whereis 74.125.67.100
<sp33chy> : 74.125.67.100 ~ country code: US ~ country: United States ~ state: California ~ city: Mountain View ~ IP postcode: 94043 ~ latitude: 37.4192 ~ longitude: -122.0574 ~ ISP of this IP : Google
<sp33chy> Organization: Google ~ Host of this IP: : gw-in-f100.google.com ~ Local time in United States: 2009-04-22 18:19 |
| Code: | bind pub -|- !whereis whereis
setudef flag whereis
proc whereis {nick uhost hand chan text} {
# flag
if {![channel get $chan whereis]} { return }
# useragent
::http::config -useragent "Mozilla/5.0 ; Gecko"
# geturl, with error handler
catch { set http [::http::geturl "http://www.ip-adress.com/ip_tracer/$text" -timeout 5000] } error
# error condition 1: invalid http session
if {![string match -nocase "::http::*" $error]} {
putserv "privmsg $chan :[string totitle $error] \( http://www.ip-adress.com/ip_tracer/$text \)"
return 0
}
# error condition 2: http error
if {![string equal -nocase [::http::status $http] "ok"]} {
putserv "privmsg $chan :[string totitle [::http::status $http]] \( http://www.ip-adress.com/ip_tracer/$text \)"
return 0
}
# no error, get data
set data [::http::data $http]
# cleanup http token
::http::cleanup $http
# cleanse html for parsing
regsub -all {\[<.*?>\]} $data "" data
regsub -all "<script.*?>.*?</script>" $data "" data
regsub -all "<a href.*?</a>" $data "" data
regsub -all "<img src=.*?>" $data "" data
regsub -all {(?:\n|\t|\v|\r|</span>)} $data "" data
regsub -all {<span.*?>} $data "" data
# can we retrieve table fields?
while {[regexp -nocase -- {<th>(.*?)</th>.*?<td>(.*?)</td>} $data x type attrib]} {
# yes, store table fields into output list
lappend output "[string map {"IP country code" "country code" "IP address" ""} [string trim $type]] [string trim $attrib]"
# remove table field already retrieved and loop
regsub -nocase -- {<th>.*?</th>.*?<td>.*?</td>} $data "" data
}
# do we have output?
if {[info exists output]} {
# yes, spam first 9
puthelp "privmsg $chan :[join [lrange $output 0 8] " ~ "]"
# more than 9?
if {[llength $output] > 8} {
# yes, spam the rest
puthelp "privmsg $chan :[join [lrange $output 9 [llength $output]] " ~ "]"
}
} else {
# we have no output, declare
puthelp "privmsg $chan :$text returns no useful information for me to reply with... ;/"
}
# eof
} |
That other one had no error handlers what so ever, except for not being able to scrape useful results. This one has robust and complete error handling. Have a fun
Remember to " .chanset #yourchan +whereis " to enable functionality as usual. And keep in mind, this site throttles your requests eventually into a blackhole known as... well, very quickly after using this script your going to be seeing alot of the output shown below... _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
Sydneybabe Op
Joined: 27 Apr 2007 Posts: 106 Location: Philippines
|
Posted: Fri Apr 24, 2009 2:42 pm Post subject: |
|
|
Good day speechles, I try your script but an error occured on partyline which bot doesn't response.
| Quote: | | Tcl error [whereis]: invalid command name "::http::config" |
|
|
| Back to top |
|
 |
tomekk Master

Joined: 28 Nov 2008 Posts: 255 Location: Oswiecim / Poland
|
Posted: Fri Apr 24, 2009 4:34 pm Post subject: |
|
|
| Sydneybabe wrote: | Good day speechles, I try your script but an error occured on partyline which bot doesn't response.
| Quote: | | Tcl error [whereis]: invalid command name "::http::config" |
|
add line:
| Code: | | package require http |
after:
| Code: | | setudef flag whereis |
|
|
| Back to top |
|
 |
holycrap Op
Joined: 21 Jan 2008 Posts: 152
|
Posted: Sat May 30, 2009 7:53 pm Post subject: |
|
|
Sorry to bother you guys again,
Anyway to modify the output to show only "city" and "country" and nothing else, like the original script?
Thanks much!
 |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun May 31, 2009 9:02 am Post subject: |
|
|
| holycrap wrote: | Sorry to bother you guys again,
Anyway to modify the output to show only "city" and "country" and nothing else, like the original script?
Thanks much!
 |
| Code: | #top of script somewhere add this new variable
#these are simply masks, one entry may match many
#craft these carefully and experiment. the order shown
#here is the order shown in the output.
variable whereisFilter [list "*city:*" "*country:*"]
... snipped parts not relevant...
...now down here begin your changes...
...at the very next comment...
# Start your changes with this line, copy everything below
# over what is presently in your script. use the first line below
# as an indicator of where to start this pasting over.
while {[regexp -nocase -- {<th>(.*?)</th>.*?<td>(.*?)</td>} $data x type attrib]} {
lappend output "[string totitle [string trim [string map {"IP country code" "country code" "IP address" " "} $type]]] [string trim $attrib]"
regsub -nocase -- {<th>.*?</th>.*?<td>.*?</td>} $data "" data
}
# do we have output?
if {[info exists output]} {
# yes, determine what exactly to output...
foreach entry $::whereisFilter {
foreach attribute $output {
# does the attribute match any filter masks?
if {[string match -nocase $entry [lindex [split $attribute] 0]]} {
# yes, add to spam list
lappend spamline $attribute
}
}
}
# was a spam list created?
if {[info exists spamline]} {
# if created, does it have any contents?
if {[llength $spamline]} {
# yes, spam first 9
puthelp "privmsg $chan :[join [lrange $spamline 0 8] " ~ "]"
# more than 9?
if {[llength $spamline] > 8} {
# yes, spam the rest
puthelp "privmsg $chan :[join [lrange $spamline 9 [llength $spamline]] " ~ "]"
}
}
} else {
# we have output but nothing in the spam list, declare
puthelp "privmsg $chan :$text returns some useful information for me to reply with, but filtering is preventing me from showing you... ;/"
}
} else {
# we have no output at all, declare
puthelp "privmsg $chan :$text returns no useful information for me to reply with... ;/"
}
# eof
} |
These changes will allow you a variable known as whereisFilter which will contain the masks you want to show on irc. Any masks that do not fit your list will _not_ be shown. In this way you can add them all back, whatever. The order you put does matter, so you can now have them pop up in any order you desire as well as a benefit. Enjoy.
If you experience errors shout em out, this code is untested simply off the top of my head in 5 minutes.
edit: corrected missing bracket ( ] ) _________________ speechles' eggdrop tcl archive
Last edited by speechles on Sun May 31, 2009 3:05 pm; edited 1 time in total |
|
| Back to top |
|
 |
holycrap Op
Joined: 21 Jan 2008 Posts: 152
|
Posted: Sun May 31, 2009 2:46 pm Post subject: |
|
|
Hello again,
I don't know what I'm doing wrong. The bot is not responding and I'm not getting any error on partyline.
Thanks again.
| Code: | bind pub -|- !whereis whereis
setudef flag whereis
package require http
variable whereisFilter [list "*city:*" "*country:*"]
proc whereis {nick uhost hand chan text} {
# flag
if {![channel get $chan whereis]} { return }
# useragent
::http::config -useragent "Mozilla/5.0 ; Gecko"
# geturl, with error handler
catch { set http [::http::geturl "http://www.ip-adress.com/ip_tracer/$text" -timeout 5000] } error
# error condition 1: invalid http session
if {![string match -nocase "::http::*" $error]} {
putserv "privmsg $chan :[string totitle $error] \( http://www.ip-adress.com/ip_tracer/$text \)"
return 0
}
# error condition 2: http error
if {![string equal -nocase [::http::status $http] "ok"]} {
putserv "privmsg $chan :[string totitle [::http::status $http]] \( http://www.ip-adress.com/ip_tracer/$text \)"
return 0
}
# no error, get data
set data [::http::data $http]
# cleanup http token
::http::cleanup $http
# cleanse html for parsing
regsub -all {\[<.*?>\]} $data "" data
regsub -all "<script.*?>.*?</script>" $data "" data
regsub -all "<a href.*?</a>" $data "" data
regsub -all "<img src=.*?>" $data "" data
regsub -all {(?:\n|\t|\v|\r|</span>)} $data "" data
regsub -all {<span.*?>} $data "" data
# can we retrieve table fields?
while {[regexp -nocase -- {<th>(.*?)</th>.*?<td>(.*?)</td>} $data x type attrib]} {
lappend output "[string totitle [string trim [string map {"IP country code" "country code" "IP address" " "} $type]]] [string trim $attrib]"
regsub -nocase -- {<th>.*?</th>.*?<td>.*?</td>} $data "" data
}
# do we have output?
if {[info exists output]} {
# yes, determine what exactly to output...
foreach entry $::whereisFilter {
foreach attribute $output {
# does the attribute match any filter masks?
if {[string match -nocase $entry [lindex [split $attribute] 0]} {
# yes, add to spam list
lappend spamline $attribute
}
}
}
# was a spam list created?
if {[info exists spamline]} {
# if created, does it have any contents?
if {[llength $spamline]} {
# yes, spam first 9
puthelp "privmsg $chan :[join [lrange $spamline 0 8] " ~ "]"
# more than 9?
if {[llength $spamline] > 8} {
# yes, spam the rest
puthelp "privmsg $chan :[join [lrange $spamline 9 [llength $spamline]] " ~ "]"
}
}
} else {
# we have output but nothing in the spam list, declare
puthelp "privmsg $chan :$text returns some useful information for me to reply with, but filtering is preventing me from showing you... ;/"
}
} else {
# we have no output at all, declare
puthelp "privmsg $chan :$text returns no useful information for me to reply with... ;/"
}
# eof
} |
|
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun May 31, 2009 3:04 pm Post subject: |
|
|
| holycrap wrote: | Hello again,
I don't know what I'm doing wrong. The bot is not responding and I'm not getting any error on partyline.
Thanks again.
 |
In testing, because to troubleshoot this required testing what I wrote, seems I simply forgot a closing bracket ( ] ).. I've since fixed this and just pasted the entire thing for you This is tested, it works perfectly as designed. | Quote: | <speechles> !whereis google.com
<bot> City: Mountain View ~ Country: United States |
| Code: | bind pub -|- !whereis whereis
setudef flag whereis
package require http
# Set your filtered list here with or without wildcards,
# only these will be displayed and the order you choose
# here is the exact order in which it will be output. To
# display everything, all the site has to offer and see
# what there is to choose from, use a single wildcard,
# "*", in the list below.
variable whereisFilter [list "city:" "country:"]
proc whereis {nick uhost hand chan text} {
# flag
if {![channel get $chan whereis]} { return }
# useragent
::http::config -useragent "Mozilla/5.0 ; Gecko"
# geturl, with error handler
catch { set http [::http::geturl "http://www.ip-adress.com/ip_tracer/$text" -timeout 5000] } error
# error condition 1: invalid http session
if {![string match -nocase "::http::*" $error]} {
putserv "privmsg $chan :[string totitle $error] \( http://www.ip-adress.com/ip_tracer/$text \)"
return 0
}
# error condition 2: http error
if {![string equal -nocase [::http::status $http] "ok"]} {
putserv "privmsg $chan :[string totitle [::http::status $http]] \( http://www.ip-adress.com/ip_tracer/$text \)"
return 0
}
# no error, get data
set data [::http::data $http]
# cleanup http token
::http::cleanup $http
# cleanse html for parsing
regsub -all {\[<.*?>\]} $data "" data
regsub -all "<script.*?>.*?</script>" $data "" data
regsub -all "<a href.*?</a>" $data "" data
regsub -all "<img src=.*?>" $data "" data
regsub -all {(?:\n|\t|\v|\r|</span>)} $data "" data
regsub -all {<span.*?>} $data "" data
# can we retrieve table fields?
while {[regexp -nocase -- {<th>(.*?)</th>.*?<td>(.*?)</td>} $data x type attrib]} {
lappend output "[string totitle [string trim [string map {"IP country code" "country code" "IP address" " "} $type]]] [string trim $attrib]"
regsub -nocase -- {<th>.*?</th>.*?<td>.*?</td>} $data "" data
}
# do we have output?
if {[info exists output]} {
# yes, determine what exactly to output...
foreach entry $::whereisFilter {
foreach attribute $output {
# does the attribute match any filter masks?
if {[string match -nocase $entry [lindex [split $attribute] 0]]} {
# yes, add to spam list
lappend spamline $attribute
}
}
}
# was a spam list created?
if {[info exists spamline]} {
# if created, does it have any contents?
if {[llength $spamline]} {
# yes, spam first 9
puthelp "privmsg $chan :[join [lrange $spamline 0 8] " ~ "]"
# more than 9?
if {[llength $spamline] > 8} {
# yes, spam the rest
puthelp "privmsg $chan :[join [lrange $spamline 9 [llength $spamline]] " ~ "]"
}
}
} else {
# we have output but nothing in the spam list, declare
puthelp "privmsg $chan :$text returns some useful information for me to reply with, but filtering is preventing me from showing you... ;/"
}
} else {
# we have no output at all, declare
puthelp "privmsg $chan :$text returns no useful information for me to reply with... ;/"
}
# eof
} |
_________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
holycrap Op
Joined: 21 Jan 2008 Posts: 152
|
Posted: Sun May 31, 2009 3:46 pm Post subject: |
|
|
Hi,
The bot keeps giving me this:
<holycrap> !whereis google.com
<bot> Timeout ( http://www.ip-adress.com/ip_tracer/google.com )
Last edited by holycrap on Sun May 31, 2009 3:53 pm; edited 1 time in total |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun May 31, 2009 3:48 pm Post subject: |
|
|
Maybe raise the timeout in this line from 5000 to 10000? | Code: | | catch { set http [::http::geturl "http://www.ip-adress.com/ip_tracer/$text" -timeout 5000] } error |
_________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
holycrap Op
Joined: 21 Jan 2008 Posts: 152
|
Posted: Sun May 31, 2009 3:58 pm Post subject: |
|
|
Thanks much, it works now!
One last question. Which line do I modify if I want to add color to the output and such?
It's cool that it can find the location of a website... better if you can !whereis <nick> and not just IP.
 |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun May 31, 2009 4:08 pm Post subject: |
|
|
| holycrap wrote: | Thanks much, it works now!
One last question. Which line do I modify if I want to add color to the output and such?
It's cool that it can find the location of a website... better if you can !whereis <nick> and not just IP.
 |
It isn't a single line you would need to change. The method of deployment must be changed as well. The script simply builds a list to spam to the screen based upon the output list it received and comparing this to your filter list. So it doesn't really know which order you've done or anything, only you do. | Code: | # if created, does it have any contents?
if {[llength $spamline]} {
# yes, spam first 9
puthelp "privmsg $chan :[join [lrange $spamline 0 8] " ~ "]"
# more than 9?
if {[llength $spamline] > 8} {
# yes, spam the rest
puthelp "privmsg $chan :[join [lrange $spamline 9 [llength $spamline]] " ~ "]"
}
} |
You can change this and "hard-code" it to always assume city and country are those 2. | Code: | # if created, does it have any contents?
if {[llength $spamline]} {
# pluck just the city from the spamline
set city [string trim [lindex [split [lindex $spamline 0] :] 1]]
# pluck just the country from spamline
set country [string trim [lindex [split [lindex $spamline 1] :] 1]]
# spam our newly created variables
puthelp "privmsg $chan :City: $city ~ Country: $country"
} |
This assumes your filter list will only ever be city and country, and in that order. If you change the filter list you will need to change this "hard-coded" segment. This should allow you to customize it as you wish.
To make it able to do it by nick requires that nick be in the channel you issue the command in. So find this: | Code: | # flag
if {![channel get $chan whereis]} { return } | Then under it, add this code. | Code: | if {![string match "*.*" $text]} {
set wnick [lindex [split [getchanhost [lindex [split $text] 0] $chan] @] 1]
if {[string length $wnick]} { set text $wnick }
} |
_________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
holycrap Op
Joined: 21 Jan 2008 Posts: 152
|
Posted: Sun May 31, 2009 4:28 pm Post subject: |
|
|
That "nick" part didn't work, but it's all good, thanks for your time.
| Code: | To make it able to do it by nick requires that nick be in the channel you issue the command in. So find this:
Code:
# flag
if {![channel get $chan whereis]} { return }
Then under it, add this code.
Code:
if {![string match "*.*" $text]} {
set wnick [lindex [split [getchanhost [lindex [split $text] 0] $chan] @] 1]
if {[string length $wnick]} { set text $wnick }
} |
|
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun May 31, 2009 4:39 pm Post subject: |
|
|
| holycrap wrote: | That "nick" part didn't work, but it's all good, thanks for your time.
| Code: | To make it able to do it by nick requires that nick be in the channel you issue the command in. So find this:
Code:
# flag
if {![channel get $chan whereis]} { return }
Then under it, add this code.
Code:
if {![string match "*.*" $text]} {
set wnick [lindex [split [getchanhost [lindex [split $text] 0] $chan] @] 1]
if {[string length $wnick]} { set text $wnick }
} |
|
It does work, but getchanhost has a limitation of course that being the fact it is tied to a particular channel. If the nick is in the same channel as the person issuing the command, this does work. It should work equally for you If you insert the code correctly below the line with ![channel get]. _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
holycrap Op
Joined: 21 Jan 2008 Posts: 152
|
Posted: Sun May 31, 2009 4:43 pm Post subject: |
|
|
Is it possible the server I'm running on masked the trailing digits of the IP address and is messing with the code?
| Code: | # flag
if {![channel get $chan whereis]} { return }
if {![string match "*.*" $text]} {
set wnick [lindex [split [getchanhost [lindex [split $text] 0] $chan] @] 1]
if {[string length $wnick]} { set text $wnick }
}
|
Last edited by holycrap on Sun May 31, 2009 5:15 pm; edited 1 time in total |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|