Difference between revisions of "Little sockets tutorial"

From Scriptwiki
Jump to: navigation, search
(links enabled)
Line 1: Line 1:
This tutorial shows how to use sockets to get info from http://checkip.dyndns.org/index.php and how to use that info to set the ip in mirc correct. This can be usefull if you've a router and a bnc.
+
This tutorial shows how to use [[sockets]] to get info from http://checkip.dyndns.org/index.php and how to use that info to set the ip in mirc correct. This can be usefull if you've a router and a bnc.
  
  <nowiki>;this is a little tutorial about sockets
+
  ;this is a little tutorial about sockets
;
+
;
;it's about how to connect to http://checkip.dyndns.org/index.php with mirc, then take your ip out
+
;it's about how to connect to http://checkip.dyndns.org/index.php with mirc, then take your ip out
;
+
;
;and use that ip to set $ip
+
;and use that ip to set $ip
;
+
;
;this can be usefull if you've a router and a bnc, depending on your mirc settings, mirc will normally
+
;this can be usefull if you've a router and a bnc, depending on your mirc settings, mirc will normally
;make $ip your bnc serverip, or your local ip, like 192.168.0.2
+
;make $ip your bnc serverip, or your local ip, like 192.168.0.2
;
+
;
;
+
;
 +
 +
 +
;on connect event, with timer, so if you connect to 3 different servers on start up, it'll only be triggered once :)
 +
[[On_connect|on *:connect]]:{ .[[timer]]myip 1 5 myip }
 +
 +
 +
[[Aliases|alias]] myip {
 +
  ;if the socket already is open, close it, you can only have one connection with the same name at the same time
 +
  [[If-Then-Else|if]] ([[$sock]](myip)) { [[sockclose]] myip }
 +
  ;to open a socket with name myip to address checkip.dyndns.org on port 80
 +
  sockopen myip checkip.dyndns.org 80
 +
}
 +
;this event is triggered on the moment the sockets is opened
 +
[[On_Sockopen|on *:sockopen]]:myip:{
 +
  ;to tell the server which file you want to receive
 +
  [[sockwrite]] -n $sockname GET /index.php HTTP/1.0
 +
  sockwrite -n $sockname Host: checkip.dyndns.org
 +
  ;this is only needed for a few websites, but it's just more complete to have it ;)
 +
  sockwrite -n $sockname user-agent: Mozilla/??
 +
  sockwrite -n $sockname Connection: Keep-Alive
 +
  sockwrite -n $sockname $crlf
 +
}
 +
on 1:sockread:myip:{
 +
  ;same way as in mirc helpfile with the :nextread
 +
  if ($sockerr > 0) [[return]]
 +
  :nextread
 +
  sockread %temp
 +
  if ($sockbr == 0) return
 +
  ;to check if we got the right line, it's pretty easy for this file, but usually more complicated,
 +
  ;use $gettok or variables to get the right line.
 +
  if (<html> [[isin]] %temp) {
 +
    ;%temp will contain something like:
 +
    ;<html><head><title>Current IP Check</title></head><body>Current IP Address: 217.20.116.184</body></html>
 +
    ;an easy way to 'strip' it is with $remove
 +
    [[var]] %z = $remove(%temp,<html><head><title>Current IP Check</title></head><body>Current IP Address:,</body></html>)
 +
 +
    ;scon -a is to send a command to all servers mirc is connected to
 +
    [[scon]] -a localinfo [[$chr]](10) %z
 +
    scon -a [[echo]] 4 -s ip is set to $ip
 +
  } 
 +
  [[Goto_loops|goto]] nextread
 +
}
 +
 +
;If your knowledge about sockets is still [[$null]] or just not enough yet ;), maybe read this tutorial:
 +
; http://www.mircscripts.org/showdoc.php?type=tutorial&id=1128 or check /help Sockets</nowiki>
  
 
;on connect event, with timer, so if you connect to 3 different servers on start up, it'll only be triggered once :)
 
on *:connect:{ .timermyip 1 5 myip }
 
 
 
alias myip {
 
;if the socket already is open, close it, you can only have one connection with the same name at the same time
 
if ($sock(myip)) { sockclose myip }
 
;to open a socket with name myip to address checkip.dyndns.org on port 80
 
sockopen myip checkip.dyndns.org 80
 
}
 
;this event is triggered on the moment the sockets is opened
 
on *:sockopen:myip:{
 
;to tell the server which file you want to receive
 
sockwrite -n $sockname GET /index.php HTTP/1.0
 
sockwrite -n $sockname Host: checkip.dyndns.org
 
;this is only needed for a few websites, but it's just more complete to have it ;)
 
sockwrite -n $sockname user-agent: Mozilla/??
 
sockwrite -n $sockname Connection: Keep-Alive
 
sockwrite -n $sockname $crlf
 
}
 
on 1:sockread:myip:{
 
;same way as in mirc helpfile with the :nextread
 
if ($sockerr > 0) return
 
:nextread
 
sockread %temp
 
if ($sockbr == 0) return
 
;to check if we got the right line, it's pretty easy for this file, but usually more complicated,
 
;use $gettok or variables to get the right line.
 
if (<html> isin %temp) {
 
  ;%temp will contain something like:
 
  ;<html><head><title>Current IP Check</title></head><body>Current IP Address: 217.20.116.184</body></html>
 
  ;an easy way to 'strip' it is with $remove
 
  var %z = $remove(%temp,<html><head><title>Current IP Check</title></head><body>Current IP Address:,</body></html>)
 
 
  ;scon -a is to send a command to all servers mirc is connected to
 
  scon -a localinfo $chr(10) %z
 
  scon -a echo 4 -s ip is set to $ip
 
 
goto nextread
 
}
 
 
;If your knowledge about sockets is still $null or just not enough yet ;), maybe read this tutorial:
 
; http://www.mircscripts.org/showdoc.php?type=tutorial&id=1128 or check /help Sockets</nowiki>
 
 
[[Category:Script Archive]]
 
[[Category:Script Archive]]

Revision as of 07:26, 25 August 2005

This tutorial shows how to use sockets to get info from http://checkip.dyndns.org/index.php and how to use that info to set the ip in mirc correct. This can be usefull if you've a router and a bnc.

;this is a little tutorial about sockets
;
;it's about how to connect to http://checkip.dyndns.org/index.php with mirc, then take your ip out
;
;and use that ip to set $ip
;
;this can be usefull if you've a router and a bnc, depending on your mirc settings, mirc will normally
;make $ip your bnc serverip, or your local ip, like 192.168.0.2
;
;


;on connect event, with timer, so if you connect to 3 different servers on start up, it'll only be triggered once :)
on *:connect:{ .timermyip 1 5 myip }


alias myip {
 ;if the socket already is open, close it, you can only have one connection with the same name at the same time
 if ($sock(myip)) { sockclose myip }
 ;to open a socket with name myip to address checkip.dyndns.org on port 80
 sockopen myip checkip.dyndns.org 80
}
;this event is triggered on the moment the sockets is opened
on *:sockopen:myip:{
 ;to tell the server which file you want to receive
 sockwrite -n $sockname GET /index.php HTTP/1.0
 sockwrite -n $sockname Host: checkip.dyndns.org
 ;this is only needed for a few websites, but it's just more complete to have it ;)
 sockwrite -n $sockname user-agent: Mozilla/??
 sockwrite -n $sockname Connection: Keep-Alive
 sockwrite -n $sockname $crlf
}
on 1:sockread:myip:{
 ;same way as in mirc helpfile with the :nextread
 if ($sockerr > 0) return
 :nextread
 sockread %temp
 if ($sockbr == 0) return
 ;to check if we got the right line, it's pretty easy for this file, but usually more complicated,
 ;use $gettok or variables to get the right line.
 if (<html> isin %temp) {
   ;%temp will contain something like:
   ;<html><head><title>Current IP Check</title></head><body>Current IP Address: 217.20.116.184</body></html>
   ;an easy way to 'strip' it is with $remove
   var %z = $remove(%temp,<html><head><title>Current IP Check</title></head><body>Current IP Address:,</body></html>)

   ;scon -a is to send a command to all servers mirc is connected to
   scon -a localinfo $chr(10) %z
   scon -a echo 4 -s ip is set to $ip
 }  
 goto nextread
}

;If your knowledge about sockets is still $null or just not enough yet ;), maybe read this tutorial:
; http://www.mircscripts.org/showdoc.php?type=tutorial&id=1128 or check /help Sockets</nowiki>