mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: May 2006
Posts: 93
Babel fish
OP Offline
Babel fish
Joined: May 2006
Posts: 93
I made a IP2Locator script and it works perfectly.
Before publishing it, some friends have tested it and everyone tell me that it doesn't work.

The problem seems to be in this part of the script:
Code:
 if (<p><center><table> isin %ip) {
      sockread 950 &ip
      sockread 512 &ip
      %ip = $bvar(&ip,1,$bvar(&ip,0)).text

When i read from the site i have
<p><center><table> <950bytes of useless data> <512bytes with all the info i need>.
I read and ignore the first 950bytes and then i read the other 512bytes.

I ask them to try
Code:
 if (&lt;p&gt;&lt;center&gt;&lt;table&gt; isin %ip) {
      sockread 950 &amp;ip
      bwrite $+(",$scriptdir,test1.txt,") 0 &amp;ip
      sockread 512 &amp;ip
      bwrite $+(",$scriptdir,test2.txt,") 0 &amp;ip
      %ip = $bvar(&amp;ip,1,$bvar(&amp;ip,0)).text

and they tell me that the first sockread reads from the buffer and write on test1.txt but the second one doesn't work and test2.txt is empty.

I tried several things
Code:
if (&lt;p&gt;&lt;center&gt;&lt;table&gt; isin %ip) {
      sockread 950 &amp;ip2
      sockread 512 &amp;ip
      %ip = $bvar(&amp;ip,1,$bvar(&amp;ip,0)).text
or
Code:
if (&lt;p&gt;&lt;center&gt;&lt;table&gt; isin %ip) {
     sockread 1462 &amp;ip
     bwrite $+(",$scriptdir,test.txt,") 0 &amp;ip
     %ip = $bvar(&amp;ip,951,512).text
     echo -s %ip

All these things works on my pc, but they don't works on my friends pcs and i can understand why. We all have mirc 6.17 and win xp sp2.

The 512bytes of info that I need are something like this
Code:
&gt;&lt;td nowrap align=center&gt;213.203.143.50&lt;/td&gt;&lt;td nowrap align=center&gt;IT&lt;/td&gt;&lt;td nowrap align=center&gt;ITALY&lt;/td&gt;&lt;td nowrap align=center&gt;&lt;img src=/flags/IT.gif&gt;&lt;/img&gt;&lt;/td&gt;&lt;td nowrap align=center&gt;LAZIO&lt;/td&gt;&lt;td nowrap align=center&gt;ROME&lt;/td&gt;&lt;td nowrap align=center&gt;MC-LINK SPA - HOUSING SERVICES
&lt;/td&gt;&lt;td nowrap align=center&gt;&lt;a target=_new href="http://www.ip2state.com/map.asp?s=ip&amp;city=ROME&amp;lat=41.9&amp;long=12.483&amp;ses=103768809"&gt;&lt;img border=0 src="images/mapit.gif"&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt;&lt;/center&gt;&lt;p&gt;

if i use sockread %ip this part
</td><td nowrap align=center><a target=_new href="http://www.ip2state.com/map.asp?s=ip&city=ROME&lat=41.9&long=12.483&ses=103768809"><img border=0 src="images/mapit.gif"></a></td></tr> </table></center><p>
it's cutted off and the only way i found is to read and ignore the first 950bytes then read the 512bytes of info is with the use of the binvar.

I don't know how can i do, here it's work perfectly.
This is the link where you can find the script:
http://wolfprojects.altervista.org/addons.php#ip2loc
if it works you should see something like this
http://wolfprojects.altervista.org/images.php?dir=addons&id=ip2loc1.gif
elseif it doesn't you should see the edits in the dialog empty, IP2Location - Downloading flag... in the titlebar and a did -g unable to load flag.gif error in the status.
But the error isn't while loading the flag, but in the second sockread.
Between the 512bytes of info there's the address of the flag, if it can't be read the scripts download a corrupted images of the flag that cannot be loaded.
The readme is in italian, use /ip2loc to load the dialog, "Find location" to start the search, "P" for paste an ip from the clipboard and "#" for reset the dialog.

You just have 20 credits each days.

I hope that someone can find what's the problem.
Taggnostr

Edit: just a few error with my english. :P
Edit2: The people who try it tell me this
4: never works
1: sometimes works
me and another friend of mine: always works

Last edited by Taggnostr; 21/06/06 09:17 AM.
Joined: Jan 2003
Posts: 1,063
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2003
Posts: 1,063
I think the <> are messing it up... because those are special characters used for comparison you can't use them as text in an IF.

put the info in a variable or something to counter this problem


If it ain't broken, don't fix it!
Joined: May 2006
Posts: 93
Babel fish
OP Offline
Babel fish
Joined: May 2006
Posts: 93
the "if" works and the first sockread works too, i tried this
set %ip dsafdas<p><center><table>gfdsgsdsdgf
and
//echo -a $iif(<p><center><table> isin %ip,ok,ko)
returns ok,
it's not this the problem :\

Joined: Jul 2004
Posts: 31
H
Ameglian cow
Offline
Ameglian cow
H
Joined: Jul 2004
Posts: 31
the first sockread reads only 430bytes for me which is all there is in the rq, the second sockreads reads 0bytes then of course.
never worked for all 20 tries.

Joined: May 2006
Posts: 93
Babel fish
OP Offline
Babel fish
Joined: May 2006
Posts: 93
i'd like to know why i (and some of the people who tried it) can read all.
If there are some mistakes in the script it will never work.
There must be something else that prevent the script to work but i can't understand what.
Maybe the answer of the server changes?
The stranger thing is that one of the person that try it tell me that
sometimes it works.
The problem can't depends neither from the site nor from the script because here always works.
I don't think that it depends from some configuration(?) firewall or others, because sometimes it works.
What can (always|sometimes|never) prevent the script to work?
I really can't understand :\

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
The probelm exist becuase you have assumed how much data is in the socket read buffer, im now gong to have to start assuming things as well due to the lack of code u have shown.

Im going to assume your sockreads prior to this one have been directly into %ip using /sockread %ip
I assume this as it would appear you know exactly how far to read beyond the line that contained your matched text, to get your data.
The mistake u made is assuming that there is 1462 bytes of data remaining in the buffer, if there are not then your out of luck.

heres a sheel of what you need, sicne i dont know what else your doing it might need fixing.

Code:
on *:sockread:NAME:{
  if (!$sock($sockname).mark) {
    var %ip
    sockread %ip
    if (&lt;p&gt;&lt;center&gt;&lt;table&gt; isin %ip) {
      sockmark $sockname IGNORE 512
    }
  }
  ;
  if (IGNORE * iswm $sock($sockname).mark) {
    %remaining = $gettok($v2,2,32)
    sockread %remaining &amp;ip
    if ($sockbr &lt; %remaining) {
      sockmark $sockname IGNORE $calc(%remaining - $sockbr)
    }
    else {
      set ($+(%,ip.,$sockname)
      sockmark $sockname READ 512
    }
  }
  ;
  if (READ * iswm $sock($sockname).mark) {
    %remaining = $gettok($v2,2,32)
    sockread %remaining &amp;ip
    set $+(%,ip.,$sockname) $($+(%,ip.,$sockname),2) $bvar(&amp;ip,1,$bvar(&amp;ip,0)).text
    if ($sockbr &lt; %remaining) {
      sockmark $sockname READ $calc(%remaining - $sockbr)
    }
    else {
      %ip = $($+(%,ip.,$sockname),2)
      unset ($+(%,ip.,$sockname)
      sockmark $sockname READ $calc(%remaining - $sockbr)
      ********** CONTINUE WITH YOUR %IP VALUE INTACKED HERE **********
    }
  }
}


what its designed to do is read the socket using text untill it loactes the line with the matching text in it, it then loads the sockmark with IGNORE 950
the code then drops intop the next if becuase the sockmark is now loaded for it, this well read up to 950 bytes, if it doesnt manage to read than many, say only 300, it subtracts 300 from 950 and leaves the sockmark as IGNORE 650, which well be taken up on the next sockread event, if it does read them all, then it sets sockmark to READ 512, whcih again allows the code to fall into the next if, which repeats the process, but this time also stores the data, until you have read all 512 bytes, then loads it in to %ip

if u have loads of data in the socket, it well fall right through in one shot, going
sockread %ip & matched text then sockread 950 &ip & 950 read then sockread 512 & 512 read, if not then it holds at what ever it was up too.

Joined: May 2006
Posts: 93
Babel fish
OP Offline
Babel fish
Joined: May 2006
Posts: 93
thanks for the answer, i never use sockmark but tomorrow i'll try it and see what happens.

Quote:
due to the lack of code u have shown

http://wolfprojects.altervista.org/addons.php#ip2loc <- here you can find all the code wink

Quote:
The probelm exist becuase you have assumed how much data is in the socket read buffer

the first 950bytes are the header of a table, it should be always 950 bytes, the header is always the same.

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
You miss understand, im not talking about the webpage returned. Im talking about HOW MUCH of the web page has so far been returned to you sockread buffer

example below shows all the data you need to get from the website... (lines cut at 50 charcters for easy viewing)
orange = matchtext line, red = ignored header, blue = wanted info
Code:
[color:orange]&lt;p&gt;&lt;center&gt;&lt;table&gt;[/color]
[color:red]    &lt;tr&gt;&lt;td align=center bgcolor=#0066CC bordercol
or=#FFFFCC&gt;&lt;font color=white&gt;&lt;b&gt;&amp;nbsp;IP Address&amp;n
bsp;&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;        &lt;td align=center bgcol
or=#0066CC bordercolor=#FFFFCC&gt;&lt;font color=white&gt;&lt;
b&gt;&amp;nbsp;Country (Short)&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;     
   &lt;td align=center bgcolor=#0066CC bordercolor=#F
FFFCC&gt;&lt;font color=white&gt;&lt;b&gt;&amp;nbsp;Country (Full)&amp;nb
sp;&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;        &lt;td align=center bgcolo
r=#0066CC bordercolor=#FFFFCC&gt;&lt;font color=white&gt;&lt;b
&gt;&amp;nbsp;Flag&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;        &lt;td align
=center bgcolor=#0066CC bordercolor=#FFFFCC&gt;&lt;font 
color=white&gt;&lt;b&gt;&amp;nbsp;Region&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;/td&gt; 
       &lt;td align=center bgcolor=#0066CC bordercolo
r=#FFFFCC&gt;&lt;font color=white&gt;&lt;b&gt;&amp;nbsp;City&amp;nbsp;&lt;/b
&gt;&lt;/font&gt;&lt;/td&gt;        &lt;td align=center bgcolor=#006
6CC bordercolor=#FFFFCC&gt;&lt;font color=white&gt;&lt;b&gt;&amp;nbsp
;ISP&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;        &lt;td align=center
 bgcolor=#0066CC bordercolor=#FFFFCC&gt;&lt;font color=w
hite&gt;&lt;b&gt;&amp;nbsp;Map&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;[/color]
[color:blue]&lt;td nowrap align=center&gt;127.0.0.1&lt;/td&gt;&lt;td nowrap a
lign=center&gt;-&lt;/td&gt;&lt;td nowrap align=center&gt;-&lt;/td&gt;&lt;t
d nowrap align=center&gt;&lt;img ..src=/flags/-.gif&gt;&lt;/im
g&gt;&lt;/td&gt;&lt;td nowrap align=center&gt;-&lt;/td&gt;&lt;td nowrap al
ign=center&gt;-&lt;/td&gt;&lt;td nowrap align=center&gt;LOOPBACK.
.&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;  &lt;/table&gt;&lt;/center&gt;&lt;p&gt;&lt;center&gt;
These results produced by the &lt;br&gt;IP2Location&amp;#153
; IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ISP [D
B6] June 2006 Edition Database&lt;/center&gt;&lt;/p&gt;&lt;br&gt;  &lt;
center&gt;..  &lt;form action="/free.asp" method="POST"&gt;
  IP Address[/color]


Now the following might be whats in the SOCKREAD BUFFER at the time of the ON SOCKREAD event. The rest of the webpage is YET to be sent.
Code:
[color:orange]&lt;p&gt;&lt;center&gt;&lt;table&gt;[/color]
[color:red]    &lt;tr&gt;&lt;td align=center bgcolor=#0066CC bordercol
or=#FFFFCC&gt;&lt;font color=white&gt;&lt;b&gt;&amp;nbsp;IP Address&amp;n
bsp;&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;        &lt;td align=center bgcol
or=#0066CC bordercolor=#FFFFCC&gt;&lt;font color=white&gt;&lt;
b&gt;&amp;nbsp;Country (Short)&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;     
   &lt;td align=center bgcolor=#0066CC bordercolor=#F
FFFCC&gt;&lt;font color=white&gt;&lt;b&gt;&amp;nbsp;Country (Full)&amp;nb
sp;&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;        &lt;td align=center bgcolo
r=#0066CC bordercolor=#FFFFCC&gt;&lt;font color=white&gt;&lt;b
&gt;&amp;nbsp;Flag&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;        &lt;td align
=center bgcolor=#0066CC bordercolor=#FFFFCC&gt;&lt;font 
color=white&gt;&lt;b&gt;&amp;nbsp;Region&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;/td&gt; 
       &lt;td align=center bgcolor=#0066CC bordercolo
r=#FFFFCC&gt;&lt;font color=white&gt;&lt;b&gt;&amp;nbsp;City&amp;nbsp;&lt;/b
&gt;&lt;/font&gt;&lt;/td&gt;        &lt;td align=center bgcolor=#006
6CC bordercolor=#FFFFCC&gt;&lt;font color=white&gt;&lt;b&gt;&amp;nbsp
;ISP&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;        &lt;td align=center
 bgcolor=#0066CC bordercolor=#FFFFCC&gt;&lt;font color=w
hite&gt;&lt;b&gt;&amp;nbsp;Map&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;  &lt;tr&gt;[/color]
[color:blue]&lt;td nowrap align=center&gt;127.0.0.1&lt;/td&gt;&lt;td nowrap a
lign=center&gt;-&lt;/td&gt;&lt;td nowrap[/color]


You obviously cant read 512 bytes of blue becuase you dont have 512 bytes of blue, you may at other times not even have 950 bytes of red. or any red even! you must repeatedly do ON SCCKREAD events untill you have gained all u need.

PS: my sample code should be easy to intergrate into that code by the way. (code refrence u game me)

Joined: May 2006
Posts: 93
Babel fish
OP Offline
Babel fish
Joined: May 2006
Posts: 93
If I've understood, i'm trying to read data that aren't still in the buffer.
So, if the bytes of data are less than the number of bytes i want to read, i've just to read the remaining part and add to the first.
is that right?

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
If I've understood, i'm trying to read data that aren't still in the buffer.
So, if the bytes of data are less than the number of bytes i want to read, i've just to read the remaining part and add to the first.
is that right?



Your close, it is NOT that the bytes are not STILL in the buffer, they have YET to reach the buffer, the webserver has not YET sent the complete page.

But on what to do with this problem, yes u appear to understand., ie: read what you can and then wait for more.

Joined: May 2006
Posts: 93
Babel fish
OP Offline
Babel fish
Joined: May 2006
Posts: 93
I tried using a "while"
Code:
sockread 950 &amp;ip
  var %ip.br $calc(950 - $sockbr)
  echo -s br0-&gt; %ip.br - sbr-&gt; $sockbr
  while (%ip.br &gt; 0) {
    echo -s br1-&gt; %ip.br
    sockread %ip.br &amp;ip
    %ip.br = $calc(%ip.br - $sockbr)
    echo -s br1.5-&gt; %ip.br - sbr-&gt; $sockbr
  }

but the second sockread always read 0 byte and mirc crash.

Maybe now I found an easier way, but i've another problem.
If i read using a normal sockread %ip i reach the blue lines with the info that i need.
Code:
 [color:blue]&gt;&lt;td nowrap align=center&gt;83.184.189.90&lt;/td&gt;&lt;td nowrap align=center&gt;IT&lt;/td&gt;&lt;td nowrap align=center&gt;ITALY
 (...) &lt;td nowrap align=center&gt;TELE2 ITALY S.A  [/color]  

at the end of the lines there is a CRLF then there's this line
Code:
 [color:green] &lt;/td&gt;&lt;td nowrap align=center&gt;&lt;a target=_new href="http://www.ip2state.com/map.asp?s=ip&amp;city=REDMOND&amp;lat=47.6738&amp;long=-122.089&amp;ses=457666932"&gt;&lt;img border=0 src="images/mapit.gif"&gt;
 (...) &lt;center&gt; [/color]  

and last
Code:
  [color:red]   &lt;form action="/free.asp" method="POST"&gt; [/color]  


Now, when I read, in the var i've the blue part, if i read again in the var i've the red one, the green one seems disappear.

Just after the first sockread i did an echo of the bytes read and they was 496, but, in the %var, there are just 265bytes (the blue part).
It seems to read the blue and the green part from the buffer but just the green part go in the var.

This is the code i'm using (i also tried several combination with and without binvar)
Code:
 
  if (&amp;nbsp;Map&amp;nbsp; isin %ip) {
      ;&amp;nbsp;Map&amp;nbsp; is in the line just before the blue part
      sockread 512 &amp;ip
      ;here i read the blue and the green part
      set %ip $bvar(&amp;ip,1,$sockbr).text
      ;here i copy all the bytes read
      echo -s br-&gt; $sockbr ip-&gt; %ip
      ...
}

but the echo is:
br-> 496 ip-> ><td nowrap align=center>83.184.189.90</td><td nowrap align=center>IT</td><td nowrap align=center>ITALY</td> (...) <td nowrap align=center>TELE2 ITALY S.A
is the var cut when there is the CRLF at the end of this line?
i also tried to write the var in the file but there's no way to see the green part :\


Link Copied to Clipboard