This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Get location info from www.example.com

Help for those learning Tcl or writing their own scripts.
p
popolare
Voice
Posts: 6
Joined: Sun Mar 25, 2007 11:51 am

Get location info from www.example.com

Post by popolare »

Hello,

i'm not hard with regular expressions (regexp) so I would be really happy if someone can help me with this:

Code: Select all

proc ipaddress {nick uhost hand chan text} {
	set text [split [string trim $text]]
	if {$text == ""} {puthelp "PRIVMSG $chan :Please supply an IP number or hostname address.";return}
	set ipaddressquery [::http::formatQuery iq "$text"]
	set ipaddressurl "http://www.example.com"
	set page ""
	catch {set page [::http::geturl $ipaddressurl -query $ipaddressquery -timeout $::ipltout]} error

	set html [::http::data $page]
	::http::cleanup $page
	set city "";

	regexp {.*? IP Address city:.*?size="2">(.*?) .*?} $html match city
	puthelp "PRIVMSG $chan :ipaddress results for '$text': $city"
	return
}
where $text is an IP
the proc is works but return empty $city..
Sure the regexp i'm using is wrong..
It would be cool to get most info of ip for country, city and isp

If anyone can help it would be amazing..
Thanks in advance.

Popolare


EDIT by user: this looks like spam - the site mentioned is not a ip location service. (i changed all the urls to example.com)
J
JAFO
Voice
Posts: 19
Joined: Thu Oct 13, 2005 1:18 pm

Post by JAFO »

i aint good at scripting , but perhaps ya can work from this script.
p
popolare
Voice
Posts: 6
Joined: Sun Mar 25, 2007 11:51 am

Post by popolare »

JAFO wrote:i aint good at scripting , but perhaps ya can work from this script.
I'm already using this script but it doesn't have results from example.com

So i need right regexp to catch results from example.com
If someone can look please share your suggestions.

P.S.: JAFO, thanks anyway for script, i'm sure it will be usefull to many users if someone help us to add results from example.com (they have very fresh database with more than 93% accuracy!) to this script..

Thanks to everyone who will contribuite!
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Nobody can help you unless you state what website needs to be accessed instead of "example.com."
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

You might be interested in ipcheck.tcl.
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Also http://members.dandy.net/~fbn/iplocator.tcl.txt
Uses antonline, geobytes and DNS-Stuff's ip geolocation pages.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Actually, now that I looked at the code poopalare posted, that IS my script, butchered and minus credit.
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

popolare wrote:I'm already using this script but it doesn't have results from example.com
Apparently the user doesn't like it rosc2112. :lol:
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
p
popolare
Voice
Posts: 6
Joined: Sun Mar 25, 2007 11:51 am

Post by popolare »

rosc2112 wrote:Actually, now that I looked at the code poopalare posted, that IS my script, butchered and minus credit.
Hello rosc2112,

it's just extract from your script.
It works fine with antonline, geoip, dnsstuff.

What I need is to make it work with ip-address .com (this is not spam, even if the aren't geolocation service they have very fresh and precise database)

Anyone still can help me?

They are using POST method of form (but geoip uses it too in your iplocator.tcl) just regexp must be adapted...
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

I don't see any ip lookup on that site, it just looks like a parked website.. Give me the url for the actual up lookup and I'll add it to the script.
p
popolare
Voice
Posts: 6
Joined: Sun Mar 25, 2007 11:51 am

Post by popolare »

rosc2112 wrote:I don't see any ip lookup on that site, it just looks like a parked website.. Give me the url for the actual up lookup and I'll add it to the script.
Sorry, i spelled url incorrectly.
The correct url is http://www.ip-adress.com and the form is in homepage.

Thank you very much.

P.S.: Your script iplocator.tcl works like a charm!
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Ok, I tried this for hours, trying to figure out why it's only returning MY address, despite what the query is asking for, but it seems like the only way the form works is if you actually submit it from the webpage, which doesn't make sense to me, because the query string used by the bot is exactly the same..

Code: Select all

proc ipadrlocate {nick chan text} {
        set ipadrurl "http://www.ip-adress.com/"
        set page "";set ipcountry "";set ipstate "";set ipcity "";set iplat ""
        set iplong "";set ipisp "";set iporg ""
        set ipspeed "";set ipadrtemp "";set html ""
        set ipadrquery [::http::formatQuery iq "[join $text]" submit "lookup any ip"]
        catch {set page [::http::geturl $ipadrurl -timeout $::ipltout -query $ipadrquery]} error
        putcmdlog "text '$text'  query '$ipadrquery'"
        if {[string match -nocase "*couldn't open socket*" $error]} {
                puthelp "PRIVMSG $chan :Error: Couldn't connect to IP-Adress.com..Try again later"
                ::http::cleanup $page
                return
        }
        if {[::http::status $page] == "timeout"} {
                puthelp "PRIVMSG $chan :Error: Connection to IP-Adress.com timed out."
                ::http::cleanup $page
                return
        }
        set html [::http::data $page]
        ::http::cleanup $page

# this regexp is word-wrapped 

 if {[regexp {>My ip address:</font>.*?<font.*?>(.*?)</font>.*?>IP
country:</font>.*?<img src="/flags/.*?png">(.*?)</font>.*?>IP.*?Address
state:</font>.*?<font.*?>(.*?)</font>.*?>IP.*?Address
city:</font>.*?<font.*?>(.*?)</font>.*?>IP
latitude:</font>.*?<font.*?>(.*?)</font>.*?>IP  
longitude:</font>.*?<font.*?>(.*?)</font>.*?>isp:</font>.*?<font.*?>(.*?)</font>.*?>organization:</font>.*?<font.*?>(.*?)</font>.*?>your
speed:</font>.*?<font.*?>(.*?)</font>} $html match ipcountry ipstate ipcity
iplat iplong ipisp iporg ipspeed]} {

# other formatting junk deleted for brevity

}
The other procs I use for the binds and for resolving hostnames to ip's has been omitted for brevity.

If anyone can shed some light as to why the form on ip-adress.com won't accept the query from the bot, that would be appreciated.

Otherwise, the script would be working, I have everything else working, the regexp works, and I have the output formatted and all, I just can't figure out why every query is returning my address info (the default when you 1st load the page.)

I've run a bunch of tests from lynx, but the result is the same. It's like ip-adress.com won't accept any query unless it's sent directly from the page's submit button.. It's not cookies or java, cos I have that disabled in lynx.. There's no persistent state either, so it's not that. I did a trace log from lynx to check the actual query string being sent and I have that right too, afaict.. As far as I can tell, the above should work but... I thought it might've been the urlencoding, so I changed that as well, made no diff.

The only vague guess I have: the problem may be when the formatQuery turns the dots in the ip into %2e which is what it's supposed to do, and presumably it's what all browsers do when a query is sent. If that is indeed the problem, I see no way around it, as formatQuery doesn't provide any way of sending literal chars, that I know of.

BTW, I don't think ip-adress.com's db is all that special, compared to the other 3 I already use in the script. It places my IP far from where I am actually located, where the other 3 place it much closer (anti-online places it at the nearest CO; the other 2 get the NOC; ip-adress, I have no idea where it's getting it's data..)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

What if you make your script first load the form? (in case they use some server-side session tracking)
NML_375
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

I'm not sure I know how to do that, can you explain?

I had tried loading the page twice basically, once as a normal geturl, then as a query, but same result, it gives me my own address info, not the query's.

The other idea I had would be to use the socket code which would keep the connection open for get'ing the page, then sending the query.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Making a webservice depend on keepalive does'nt sound like a viable solution, but then again I'm not developing that ip-adress service.

As for the queries submitted, did some digging with ethereal, and the urlencoded data looked like this (for bogus ip 123.456.789.0)

Code: Select all

iq=123.456.789.0&submit=lookup+any+ip
with a content-type of "application/x-www-form-urlencoded". Nothing else fancy in the headers (tested using Firefox).

My suggestion was which you've already tried. Sorry I missed your note on not being state persistent either.
NML_375
Post Reply