mIRC Home    About    Download    Register    News    Help

Print Thread
Help socket #249194 17/11/14 08:05 PM
Joined: Nov 2014
Posts: 149
J
JuanAm Offline OP
Vogon poet
OP Offline
Vogon poet
J
Joined: Nov 2014
Posts: 149
I need to modify this code:
Code:
alias ip {

  if ($1 == $null) { echo -a 10 You must enter the IP address to find, in this format 12 $+ /ip 111.111.111.111 | return }

  if ($sock(InfoIP) != $null) sockclose InfoIP

  set %InfoIP $1

  sockopen InfoIP geoip.flagfox.net 80

  echo -ae 9,1Seeking information of IP: %InfoIP

}

on 1:sockopen:InfoIP: {

  if ($sockerr > 0) { echo -a 9,1Could not connect to the page. }

  else {

    sockwrite -nt $sockname GET geoip.flagfox.net $+ %InfoIP $+ &ip= $+ %InfoIP HTTP/1.1

    sockwrite -nt $sockname Host: geoip.flagfox.net:80

    sockwrite -nt $sockname Connection: close

    sockwrite -nt $sockname $crlf

  }
}


on 1:sockread:InfoIP: {

  :VerInfoIP

  sockread -f %DatosIP

  if ($sockbr == 0) { return }

  if (<title> isin %DatosIP) { echo -ae 5Title: $gettok($gettok(%DatosIP,2,62),1,60) }

  if (Hostname isin %DatosIP) echo -a 12Hostname:1 $gettok(%DatosIP,2,58)

  if (Continent isin %DatosIP) echo -a 12Continent:1 $gettok(%DatosIP,2,58)

  if (Country isin %DatosIP) echo -a 12Country:1 $gettok(%DatosIP,2,58)

  if (Metropolis isin %DatosIP) echo -a 12Metropolis:1 $gettok(%DatosIP,2,58)

  if (City isin %DatosIP) echo -a 12City:1 $gettok(%DatosIP,2,58)

  if (IP Address isin %DatosIP) echo -a 12IP:1 $gettok(%DatosIP,2,58)

  if (ISP isin %DatosIP) echo -a 12ISP:1 $gettok(%DatosIP,2,58)

  if (Country Code isin %DatosIP) echo -a 12Country Code:1 $gettok(%DatosIP,2,58)

  goto VerInfoIP

}

on 1:sockclose:InfoIP: { echo -a 4Search Completed! }


I think the wrong line is:
Code:
sockwrite -nt $sockname GET geoip.flagfox.net  $+ %InfoIP $+ &ip= $+ %InfoIP HTTP/1.1


With this code I want extract Ip data from the web: http://geoip.flagfox.net/

Example: 186.127.20.22
/ip 186.127.20.22

Result:
Quote:
Title: 400 Bad Request


Expected result:
Quote:

Hostname: host220.186-127-20.telecom.net.ar
Continent: South America
Country: Argentina
Region: Unknown
City: Unknown
IP:186.127.20.22
ISP: Telecom Argentina S.A. (AS7303)
Country Code:AR (ARG)



Last edited by JuanAm; 17/11/14 08:44 PM. Reason: Copy error
Re: Help socket [Re: JuanAm] #249195 17/11/14 08:12 PM
Joined: Jun 2014
Posts: 248
B
Belhifet Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Jun 2014
Posts: 248
sockwrite -nt $sockname GET geoip.flagfox.net(two spaces) $+ %InfoIP $+ &ip
sockwrite -nt $sockname GET geoip.flagfox.net(one space) $+ %InfoIP $+ &ip

on 1(one space) :sockread:InfoIP: {
on 1(no space):sockread:InfoIP: {

Last edited by Belhifet; 17/11/14 08:12 PM.
Re: Help socket [Re: Belhifet] #249196 17/11/14 08:35 PM
Joined: Nov 2014
Posts: 149
J
JuanAm Offline OP
Vogon poet
OP Offline
Vogon poet
J
Joined: Nov 2014
Posts: 149
Originally Posted By: Belhifet
sockwrite -nt $sockname GET geoip.flagfox.net(two spaces) $+ %InfoIP $+ &ip
sockwrite -nt $sockname GET geoip.flagfox.net(one space) $+ %InfoIP $+ &ip

on 1(one space) :sockread:InfoIP: {
on 1(no space):sockread:InfoIP: {


This was copy error.
Not working.

Last edited by JuanAm; 17/11/14 08:45 PM.
Re: Help socket [Re: JuanAm] #249197 17/11/14 09:04 PM
Joined: Jan 2004
Posts: 1,282
L
Loki12583 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,282
Code:
sockwrite -nt $sockname GET /?ip= $+ %InfoIP HTTP/1.1


You should note that this site prevents automated requests with captcha support.

Re: Help socket [Re: Loki12583] #249198 17/11/14 09:14 PM
Joined: Nov 2014
Posts: 149
J
JuanAm Offline OP
Vogon poet
OP Offline
Vogon poet
J
Joined: Nov 2014
Posts: 149
Originally Posted By: Loki12583
Code:
sockwrite -nt $sockname GET /?ip= $+ %InfoIP HTTP/1.1


You should note that this site prevents automated requests with captcha support.


Not working frown

Re: Help socket [Re: JuanAm] #249199 17/11/14 09:22 PM
Joined: Jan 2004
Posts: 1,282
L
Loki12583 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,282
That's not a very helpful description. I get a 200 OK response (the captcha page). If you're getting another response, please share it. Otherwise it's a parsing problem in the sockread, possibly due to requesting HTTP/1.1 instead of HTTP/1.0.

I have no interest in debugging this further, as multiple requests are blocked anyway.

Last edited by Loki12583; 17/11/14 09:25 PM.
Re: Help socket [Re: JuanAm] #249200 17/11/14 10:21 PM
Joined: Dec 2008
Posts: 1,511
westor Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
Try to use this code: http://pastebin.com/YiaUWN5h

Re: Help socket [Re: westor] #249201 17/11/14 11:38 PM
Joined: Nov 2014
Posts: 149
J
JuanAm Offline OP
Vogon poet
OP Offline
Vogon poet
J
Joined: Nov 2014
Posts: 149
Originally Posted By: westor
Try to use this code: http://pastebin.com/YiaUWN5h


Your code works perfectly to 99 %.
With ips of my country, gives incomplete information, does not show the city.
Maybe that happens with the local IPs (the country of who executes this script).
Try you with your own IP and say me.

In my ip the conditions of next line are not met:
Code:
if (*<span style="white-space: nowrap"><a href="http://en.wikipedia.org/wiki/* iswm %r) && (*target="_blank" title="* iswm %r) { echo -a 12Country:1 $httpstrip(%r) $+  }


At this conclusion came because not even shown the title "Country:"

If you have the chance to fix it is welcome, but you can fix'm also very grateful for your help and time.

Thank you!! smile


Last edited by JuanAm; 18/11/14 02:34 AM. Reason: New data !
Re: Help socket [Re: JuanAm] #249215 18/11/14 08:35 AM
Joined: Dec 2008
Posts: 1,511
westor Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
Try use this code (fixed) : http://pastebin.com/mWdAQ3Hv

NOTE 1: if the results are not correct from your FIRST try of this code i thing the problem is on the font, try change your font to : FixedSys 9 (for both and mirc script editor (Alt +r -> File -> Font) and the general mirc (Menubar -> View -> Font) font).

NOTE 2: if the problem is still then its probably something else reply here what happens.

try it.

Re: Help socket [Re: westor] #249218 18/11/14 11:26 AM
Joined: Nov 2014
Posts: 149
J
JuanAm Offline OP
Vogon poet
OP Offline
Vogon poet
J
Joined: Nov 2014
Posts: 149
I changed the font as suggested.
I've tested the code with FixedSys 9, and with other font, and the same results were obtained.
With some IPs gives more information than that contained in the web and in others less, or different data.

In spoiler I leave several examples.

Click to reveal..
THE CODE:

***** Searching informations for IP: 179.24.139.26 *****
ISP: Administracion Nacional de Telecomunicaciones (AS6057)
Continent: South America
Country Code: UY (URY)
Region: Montevideo
Local Time: 18 Nov 2014 07:54 UYST
Latitude & Longitude: -34.858, -56.171
Hostname: r179-24-139-26.dialup.adsl.anteldata.net.uy
City: Montevideo
***** End of 179.24.139.26 IP lookup *****


THE WEB:

Hostname r179-24-139-26.dialup.adsl.anteldata.net.uy
ISP Administracion Nacional de Telecomunicaciones (AS6057)
Continent South America Flag UY
Country Uruguay Country Code UY (URY)
Region Montevideo Local time 18 Nov 2014 08:40 UYST
City Montevideo Latitude -34.858
IP Address 179.24.139.26 Longitude -56.171

============================================
THE CODE:
***** Searching informations for IP: 209.186.110.182 *****
ISP: AT&T Services, Inc. (AS7018)
Continent: North America
Country: United States
Country Code: US (USA)
Region: Unknown
Local Time: 18 Nov 2014 04:06 CST
Postal Code: Unknown
Latitude & Longitude: 38, -97
Hostname: 209.186.110.182
City:
***** End of 209.186.110.182 IP lookup *****
THE WEB:
Hostname Unknown ISP AT&T Services, Inc. (AS7018)
Continent North America Flag US
Country United States Country Code US (USA)
Region Unknown Local time 18 Nov 2014 04:17 CST
Metropolis Unknown Postal Code Unknown
City Unknown Latitude 38
IP Address 209.186.110.182 Longitude -97
==============================================
THE CODE:
***** Searching informations for IP: 206.217.137.44 *****
ISP: ColoCrossing (AS36352)
Continent: North America
Country: United States
Region: New York
Local Time: 18 Nov 2014 05:10 EST
Metropolis Area: Buffalo
Postal Code: 14221
Latitude & Longitude: 42.986, -78.728
Hostname: delta.elitebnc.org
City: Buffalo
***** End of 206.217.137.44 IP lookup *****
THE WEB:
Hostname delta.elitebnc.org ISP ColoCrossing (AS36352)
Continent North America Flag US
Country United States Country Code US (USA)
Region New York Local time 18 Nov 2014 05:23 EST
Metropolis* Buffalo Postal Code 14221
City Buffalo Latitude 42.986
IP Address 206.217.137.44 Longitude -78.728
================================================
THE CODE:
***** Searching informations for IP: 190.239.94.154 *****
ISP: Telefonica del Peru S.A.A. (AS6147)
Continent: South America
Country: Peru
Country Code: PE (PER)
Region: Unknown
Local Time: 18 Nov 2014 05:00 PET
Latitude & Longitude: -10, -76
Hostname: 190.239.94.154
City:
***** End of 190.239.94.154 IP lookup *****
THE WEB:
Hostname Unknown ISP Telefonica del Peru S.A.A. (AS6147)
Continent South America Flag PE
Country Peru Country Code PE (PER)
Region Unknown Local time 18 Nov 2014 05:26 PET
City Unknown Latitude -10
IP Address 190.239.94.154 Longitude -76
===================================================
THE CODE:
***** Searching informations for IP: 186.94.189.108 *****
ISP: Servicios, Venezuela (AS8048)
Continent: South America
Country: Venezuela
Country Code: VE (VEN)
Region: Unknown
Local Time: 18 Nov 2014 06:12 VET
Latitude & Longitude: 8, -66
Hostname: 186-94-189-108.genericrev.cantv.net
City: Venezuela
***** End of 186.94.189.108 IP lookup *****

THE WEB:
Hostname 186-94-189-108.genericrev.cantv.net
ISP Servicios, Venezuela (AS8048)
Continent South America Flag VE
Country Venezuela Country Code VE (VEN)
Region Unknown Local time 18 Nov 2014 06:08 VET
City Unknown Latitude 8
IP Address 186.94.189.108 Longitude -66
====================================================

Re: Help socket [Re: JuanAm] #249222 18/11/14 03:09 PM
Joined: Dec 2008
Posts: 1,511
westor Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
Try use this code: http://pastebin.com/9JYgXPPt

And report for any errors.

Re: Help socket [Re: westor] #249223 18/11/14 05:44 PM
Joined: Nov 2014
Posts: 149
J
JuanAm Offline OP
Vogon poet
OP Offline
Vogon poet
J
Joined: Nov 2014
Posts: 149
Now, is perfect smile

Only are problems with the IPs of Uruguay, which omits putting the country.
Click to reveal..
15:10 ***** Searching informations for IP: 186.48.7.192 *****
15:10 ISP: Administracion Nacional de Telecomunicaciones (AS6057)
15:10 Continent: South America
15:10 Country Code: UY (URY)
15:10 Region: Montevideo
15:10 Local Time: 18 Nov 2014 15:10 UYST
15:10 Latitude & Longitude: -34.858, -56.171
15:10 Hostname: r186-48-7-192.dialup.adsl.anteldata.net.uy
15:10 City: Montevideo
15:10 ***** End of 186.48.7.192 IP lookup *****


I think that could be fixed with condicional 'if' to read the variable who returns 'Country Code', and if this returns UY or (URY) to set variable who returns the 'Country' in Uruguay.
Example:
If (Country Code == UY) { set Country Uruguay }
Currently not even show the title of 'Country' for IPs Uruguayans.
Should be artificially fix jajajjaa

I'm already grateful.


Re: Help socket [Re: JuanAm] #249224 18/11/14 08:09 PM
Joined: Dec 2008
Posts: 1,511
westor Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
i don't know why on your machine does NOT reply this IP the country but on my tests the Country output for this IP is correct.

Code:
[22:09:22] ***** Searching informations for IP: 179.24.139.26 *****
[22:09:24] ISP: Administracion Nacional de Telecomunicaciones (AS6057)
[22:09:24] Continent: South America
[22:09:25] Country: Uruguay
[22:09:25] Country Code: UY (URY)
[22:09:25] Region: Montevideo
[22:09:25] Local Time: 18 Nov 2014 18:09 UYST
[22:09:25] Latitude & Longitude: -34.858, -56.171
[22:09:25] Hostname: r179-24-139-26.dialup.adsl.anteldata.net.uy
[22:09:25] City: Montevideo
[22:09:26] ***** End of 179.24.139.26 IP lookup *****

Re: Help socket [Re: JuanAm] #249232 19/11/14 07:03 AM
Joined: Nov 2014
Posts: 149
J
JuanAm Offline OP
Vogon poet
OP Offline
Vogon poet
J
Joined: Nov 2014
Posts: 149
Originally Posted By: JuanAm

Your code works perfectly to 99 %.
With ips of my country, gives incomplete information, does not show the city.
Maybe that happens with the local IPs (the country of who executes this script).
Try you with your own IP and say me.

Re: Help socket [Re: JuanAm] #249247 20/11/14 04:48 PM
Joined: Nov 2014
Posts: 149
J
JuanAm Offline OP
Vogon poet
OP Offline
Vogon poet
J
Joined: Nov 2014
Posts: 149
I answer this post because I can not currently edit it.

I have translated the results of your code to the Spanish and found the reasons for IPS because some countries are not shown.

I'll leave the line of code that should be modified to contemplate these cases.
With just a few IPs the information the web changes and the line is cut.

LINES:
Code:
if (*<a href="http://es.wikipedia.org/wiki/* iswm %r) && ($left(%r,2) == <a) && (*target="_blank" title="Entrada de Wikipedia para* iswm %r) { var %esp = $replace($httpstrip(%r),&#250;,ú,&#225;,á,&#233;,é,&#237;í,&#233;ó,&#193;,Á,&#201;,É,&#205;,Í,&#211;,Ó,&#218;,Ú) | echo -at 12Continente:1 %esp $+  }
  if (*<span style="white-space: nowrap"><a href="http://es.wikipedia.org/wiki/* iswm %r) && (*target="_blank" title="Entrada de Wikipedia para* iswm %r) {
    var %country $httpstrip(%r)
    var %country = $replace(%country,&#250;,ú,&#225;,á,&#233;,é,&#237;í,&#233;ó,&#193;,Á,&#201;,É,&#205;,Í,&#211;,Ó,&#218;,Ú)
    set -e %country_ [ $+ [ $sockname ] ] %country
    echo -at 12País:1 %country $+ 


LINE TO FIX:

Code:
if (*<span style="white-space: nowrap"><a href="http://es.wikipedia.org/wiki/* iswm %r) && (*target="_blank" title="Entrada de Wikipedia para* iswm %r) {



WORK IN THIS CASE:
Click to reveal..
141412:1405 READ: <td align="left">Pa&#237;s</td>
141412:1405 READ: <td align="left" >
141412:1405 READ: <span style="white-space: nowrap"><a href="http://es.wikipedia.org/wiki/Polonia" target="_blank" title="Entrada de Wikipedia para Polonia"><b>Polonia</b></a>


NOT WORK IN THIS CASE:
Click to reveal..
141412:1407 READ: <td align="left">Pa&#237;s</td>
141412:1407 READ: <td align="left" >
141412:1407 READ: <span style="white-space: nowrap"><a href="http://es.wikipedia.org/wiki/Tailandia" target="_blank" title="Entrada de Wikipedia para Tailan
141412:1407 READ: 105b
141412:1407 READ: dia"><b>Tailandia</b></a>


As shown in the example to work, the line of Wikipedia shows all the information on one line:


Quote:
141412:1405 READ: <span style="white-space: nowrap"><a href="http://es.wikipedia.org/wiki/Polonia" target="_blank" title="Entrada de Wikipedia para Polonia"><b>Polonia</b></a>


With some IPS Wikipedia information line is cut:
Quote:
141412:1407 READ: <span style="white-space: nowrap"><a href="http://es.wikipedia.org/wiki/Tailandia" target="_blank" title="Entrada de Wikipedia para Tailan
141412:1407 READ: 105b
141412:1407 READ: dia"><b>Tailandia</b></a>


The expected information from Wikipedia for this example is:

Quote:
141412:1407 READ: <span style="white-space: nowrap"><a href="http://es.wikipedia.org/wiki/Tailandia" target="_blank" title="Entrada de Wikipedia para Tailandia"><b>Tailandia</b></a>


You can modify the code so that considers both situations?

Thank you smile

Re: Help socket [Re: JuanAm] #249250 20/11/14 07:16 PM
Joined: Dec 2008
Posts: 1,511
westor Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
Try to change all the wikipedia.org fields from the code where en.wikipedia.org into *.wikipedia.org nice grap i did not even thing that this was the problem for sick

Re: Help socket [Re: westor] #249251 20/11/14 08:24 PM
Joined: Nov 2014
Posts: 149
J
JuanAm Offline OP
Vogon poet
OP Offline
Vogon poet
J
Joined: Nov 2014
Posts: 149
Originally Posted By: westor
Try to change all the wikipedia.org fields from the code where en.wikipedia.org into *.wikipedia.org nice grap i did not even thing that this was the problem for sick


I fixed bug not very professional manner, but the results are as expected.
Only few IPs fail in each country, but I want to cover all cases.
I created a conditional When the length of the variable "%country_ [ $+ [ $sockname ] ])" is zero, take the country code for the purpose of determining the name of that country.

I wish to shorten this code line, as countries continue adding the line will be too long:

Code:
 if ($len(%country_ [ $+ [ $sockname ] ]) == 0) { $iif(UY isin %zero,echo -at 12País:1 Uruguay) | $iif(TH isin %zero,echo -at 12País:1 Tailandia) |  $iif(US isin %zero,echo -at 12País:1 Estados Unidos) | $iif(BY isin %zero,echo -at 12País:1 Bielorrusia) | $iif(IT isin %zero,echo -at 12País:1 Italia) | $iif(CO isin %zero,echo -at 12País:1 Colombia) | $iif(TR isin %zero,echo -at 12País:1 Turquía) | $iif(BR isin %zero,echo -at 12País:1 Brasil) | $iif(AR isin %zero,echo -at 12País:1 Argentina) | $iif(EC isin %zero,echo -at 12País:1 Ecuador) }

Re: Help socket [SOLVED] [Re: JuanAm] #249252 21/11/14 04:01 AM
Joined: Nov 2014
Posts: 149
J
JuanAm Offline OP
Vogon poet
OP Offline
Vogon poet
J
Joined: Nov 2014
Posts: 149
Solved!!!

Thanks to everyone who helped,especially westor.

If the moderators wish can close this thread.