mIRC Home    About    Download    Register    News    Help

Print Thread
#104092 29/11/04 08:18 PM
Joined: Aug 2004
Posts: 237
L
Fjord artisan
OP Offline
Fjord artisan
L
Joined: Aug 2004
Posts: 237
Code:
alias ip {
  sockopen whatismyip whatismyip.com 80
  echo socket opening
}
on *:sockopen:whatismyip: {
  echo socket opened  
  sockwrite -n $sockname GET / HTTP/1.0
  sockwrite -n $sockname Host: whatismyip.com $+ $crlf $+ $crlf
  echo socket written
}
on *:sockread:whatismyip: {
  echo socket reading
  echo checking for errors
  if ( $sockerr ) { echo -a Error while requesting IP: $sock($sockname).wmsg | halt }
  else {
    echo no errors, continuing
    var %temptext
    sockread %temptext
    echo var temptext: " $+ %temptext $+ "
    if ( <TITLE>Your ip is *.*.*.* WhatIsMyIP.com</TITLE> iswm %temptext ) {
      echo -a Your IP is: $htmlfree(%temptext)
    }
  }
  sockclose $sockname
  echo socket closed
}
alias htmlfree {
  echo filtering html
  var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, )
  return %x
}


Why is this code not working?
I created it following a tutorial, but it seems it doesn't work.
(I didn't literally follow the tutorial, I replaced some things to fit my needs)

I wanted to grab my ip from www.whatismyip.com and echo it to myself.

Thanks in advance!!!

I get this echoes:

Code:
socket opening
socket opened
socket written
socket reading
checking for errors
no errors, continuing
var temptext: "HTTP/1.1 200 OK"
socket closed

Joined: Mar 2004
Posts: 457
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Mar 2004
Posts: 457
you're closing the socket after the 1st pass.

ONLY close the socket on an ERROR or AFTER its gotten the info it needs. EG:


on *:sockread:whatismyip: {
echo socket reading
echo checking for errors
if ( $sockerr ) { echo -a Error while requesting IP: $sock($sockname).wmsg | sockclose $sockname | halt }
else {
echo no errors, continuing
var %temptext
sockread %temptext
echo var temptext: " $+ %temptext $+ "
if ( <TITLE>Your ip is *.*.*.* WhatIsMyIP.com</TITLE> iswm %temptext ) {
echo -a Your IP is: $htmlfree(%temptext)
sockclose $sockname
echo socket closed
}
}
}

[Edit] Also, whatsmyip is VERY unrealiable, it picks up on a transparent cache if you're using one. http://checkip.dyndns.org/ is a damn sight more accurate as to your real IP address.

Last edited by Danthemandoo; 29/11/04 09:59 PM.
Joined: Nov 2004
Posts: 842
Hoopy frood
Offline
Hoopy frood
Joined: Nov 2004
Posts: 842
why don't you just use //echo -a $ip to get your IP?


What do you do at the end of the world? Are you busy? Will you save us?
Joined: Dec 2002
Posts: 788
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 788
because, $ip can depending on your network configuration, not be your actual ip.

Eamonn.

Joined: Aug 2004
Posts: 237
L
Fjord artisan
OP Offline
Fjord artisan
L
Joined: Aug 2004
Posts: 237
I used Danthemandoo's hint but this doesn't solve the problem (I'm still using whatismyip.com, untill it works, then I'll try converting it to that other site)
I still get the same replies, no difference is seen.

Are there other solutions?

I can't use $ip 'cause it will get my local ip, not my external ip, 'cause I'm on a home network.

Joined: Apr 2004
Posts: 51
Babel fish
Offline
Babel fish
Joined: Apr 2004
Posts: 51
You can also use /localinfo -u or /localinfo -h depending on what IP it is you wish to get. -u will give you the IP that the IRC server you are connected to sees and -h will give you your internal network address. Much more reliable than any website IMO. Once the localinfo has finished $ip is set to whatever its value was.


Link Copied to Clipboard