mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2007
Posts: 5
J
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
J
Joined: Mar 2007
Posts: 5
The script is basically to use that website and get the city, state, and ISP of the user. Everytime I try to connect to the website (through mIRC) I get a 302, but if I connect through firefox it works fine. At the moment I am just trying to get the city and see if it is even possible first.
Code:
on *:DNS:{
  set %resolved $raddress
}
ALIAS iplocate {
  set %iploc 1
  sockclose iploc
  sockopen iploc www.melissadata.com 80
}
ALIAS halnohtml var %haltmp , %i = $regsub($1-,/(<[^>]+>)/g,$chr(32),%haltmp) | return %haltmp
on *:SOCKOPEN:iploc: {
  sockwrite -n $sockname GET /lookups/iplocation.asp?ipaddress= $+ %resolved HTTP/1.1
  sockwrite -n $sockname Host: www.melissadata.com
  sockwrite -n $sockname User-agent: mIRC/ $+ $version
  sockwrite -n $sockname $crlf
}

on *:SOCKREAD:iploc: {
  if ($sockerr > 0) { return }
  var %haltmp | sockread %haltmp
  echo -a %haltmp
  while ($sockbr) {
    if ( <tr><td align="right">City</td><td><b>*</b></td></tr> iswm %haltmp ) {
      set %info. [ $+ [ %iploc ] ] $halnohtml(%haltmp)
      inc %iploc
    }
    set %mytemp $halnohtml(%haltmp)
    sockread %haltmp
    echo -a %info.1
  }
}

Joined: Jul 2006
Posts: 107
L
Vogon poet
Offline
Vogon poet
L
Joined: Jul 2006
Posts: 107
I understand nothing about sockets, but a script I downloaded wouldn't work for me until
I changed HTTP/1.1 to HTTP/1.0.

Now it works just as intended.

If that doesn't solve it for you, one of the others will have to help.


LonDart
Joined: Mar 2007
Posts: 5
J
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
J
Joined: Mar 2007
Posts: 5
Originally Posted By: LonDart
I understand nothing about sockets, but a script I downloaded wouldn't work for me until
I changed HTTP/1.1 to HTTP/1.0.

Now it works just as intended.

If that doesn't solve it for you, one of the others will have to help.

I changed it to 1.0, and it echo'd HTTP/1.1 302 Object moved. I changed it to 1.9 and I got the same result. Thanks though ^^

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
1.9 is invalid anyhow. 1.0 or 1.1 are all you should be using and 1.0 is usually the best choice.

Anyhow, when is your iplocate alias being called? It's possible that your DNS entry hasn't resolved prior to trying to open the socket, or that the variable is not set properly for another reason. Try echoing %resolved to make sure that it's set right. Then, try replacing the variable with the actual link (what the variable's data is) and see if that works. That will verify if it's the variable or the connection itself that is causing the problem.


Invision Support
#Invision on irc.irchighway.net
Joined: Mar 2007
Posts: 5
J
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
J
Joined: Mar 2007
Posts: 5
Originally Posted By: Riamus2
1.9 is invalid anyhow. 1.0 or 1.1 are all you should be using and 1.0 is usually the best choice.

Anyhow, when is your iplocate alias being called?

It will just be called through a simple on text.
Originally Posted By: Riamus2

It's possible that your DNS entry hasn't resolved prior to trying to open the socket, or that the variable is not set properly for another reason. Try echoing %resolved to make sure that it's set right. Then, try replacing the variable with the actual link (what the variable's data is) and see if that works. That will verify if it's the variable or the connection itself that is causing the problem.

I am already doing this. I actually changed it to %resolved before pasting it here.

edit: I put a working IP instead of %resolved, if that clears things up in my post.

Last edited by JazzySnazzySean; 22/03/07 12:14 AM.
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
The problem is that the site you're trying to connect to uses cookies to store session data. If you don't provide the necessary cookies it uses the 302 to redirect you to http://www.melissadata.com/cgi-bin/cookie.asp.

You need to also be sending the necessary cookies in your request. To do this you have to connect to http://www.melissadata.com/lookups/iplocation.asp and parse the Set-Cookie header (it's basically just name=value pairs like HTTP GET parameters).

Unfortunately it looks like the cookies are actually manipulated by Javascript aswell so you'd need to find a way to perform the same manipulations as they appear in the source of iplocation.asp, including all the functions they call which are located in http://www.melissadata.com/cgi-bin/lib.js. I suppose you could manually read what Javascript functions are being called in iplocation.asp in the script tags and hard-code those function calls in your mIRC script, but then you'd have to create mIRC script equivalents for all the functions in lib.js. Another way might be to use COM objects and/or the Windows Script Host to run the Javascript (although that could be a major security issue).

Once that's all done you'd then have to send the cookies in your request via the Cookie header.

All in all it looks like a major headache. It's quite probable that they've intentionally done this to make it hard to programmatically use their IP Locator.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Mar 2007
Posts: 5
J
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
J
Joined: Mar 2007
Posts: 5
Originally Posted By: starbucks_mafia
The problem is that the site you're trying to connect to uses cookies to store session data. If you don't provide the necessary cookies it uses the 302 to redirect you to http://www.melissadata.com/cgi-bin/cookie.asp.

You need to also be sending the necessary cookies in your request. To do this you have to connect to http://www.melissadata.com/lookups/iplocation.asp and parse the Set-Cookie header (it's basically just name=value pairs like HTTP GET parameters).

Unfortunately it looks like the cookies are actually manipulated by Javascript aswell so you'd need to find a way to perform the same manipulations as they appear in the source of iplocation.asp, including all the functions they call which are located in http://www.melissadata.com/cgi-bin/lib.js. I suppose you could manually read what Javascript functions are being called in iplocation.asp in the script tags and hard-code those function calls in your mIRC script, but then you'd have to create mIRC script equivalents for all the functions in lib.js. Another way might be to use COM objects and/or the Windows Script Host to run the Javascript (although that could be a major security issue).

Once that's all done you'd then have to send the cookies in your request via the Cookie header.

All in all it looks like a major headache. It's quite probable that they've intentionally done this to make it hard to programmatically use their IP Locator.

Just what I didn't want to hear. There are other websites that can do this same thing. Thanks smile


Link Copied to Clipboard