Difference between revisions of "Little sockets tutorial"

From Scriptwiki
Jump to: navigation, search
m (removed <nowiki> tags)
m
 
(6 intermediate revisions by 4 users not shown)
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 [[:Category:Socket|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
 
  ;this is a little tutorial about sockets
Line 5: Line 5:
 
  ;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 useful 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
 
  ;
 
  ;
Line 21: Line 21:
 
   [[If-Then-Else|if]] ([[$sock]](myip)) { [[sockclose]] myip }
 
   [[If-Then-Else|if]] ([[$sock]](myip)) { [[sockclose]] myip }
 
   ;to open a socket with name myip to address checkip.dyndns.org on port 80
 
   ;to open a socket with name myip to address checkip.dyndns.org on port 80
   sockopen myip checkip.dyndns.org 80
+
   [[sockopen]] myip checkip.dyndns.org 80
 
  }
 
  }
 
  ;this event is triggered on the moment the sockets is opened
 
  ;this event is triggered on the moment the sockets is opened
  [[On_Sockopen|on *:sockopen]]:myip:{
+
  [[On_sockopen|on *:sockopen]]:myip:{
 
   ;to tell the server which file you want to receive
 
   ;to tell the server which file you want to receive
   [[sockwrite]] -n $sockname GET /index.php HTTP/1.0
+
   [[sockwrite]] -n [[$sockname]] GET /index.php HTTP/1.0
 
   sockwrite -n $sockname Host: checkip.dyndns.org
 
   sockwrite -n $sockname Host: checkip.dyndns.org
 
   ;this is only needed for a few websites, but it's just more complete to have it ;)
 
   ;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 user-agent: Mozilla/??
 
   sockwrite -n $sockname Connection: Keep-Alive
 
   sockwrite -n $sockname Connection: Keep-Alive
   sockwrite -n $sockname $crlf
+
   sockwrite -n $sockname [[$crlf]]
 
  }
 
  }
  on 1:sockread:myip:{
+
  [[On_sockread|on *:sockread]]:myip:{
 
   ;same way as in mirc helpfile with the :nextread
 
   ;same way as in mirc helpfile with the :nextread
   if ($sockerr > 0) [[return]]
+
   if ([[$sockerr]] > 0) [[return]]
 
   :nextread
 
   :nextread
   sockread %temp
+
   [[sockread]] %temp
   if ($sockbr == 0) return
+
   if ([[$sockbr]] == 0) return
 
   ;to check if we got the right line, it's pretty easy for this file, but usually more complicated,
 
   ;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.
 
   ;use $gettok or variables to get the right line.
   if (<html> [[isin]] %temp) {
+
   if (<html> [[If-Then-Else#isin|isin]] %temp) {
 
     ;%temp will contain something like:
 
     ;%temp will contain something like:
 
     ;<html><head><title>Current IP Check</title></head><body>Current IP Address: 217.20.116.184</body></html>
 
     ;<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
 
     ;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>)
+
     [[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 is to send a command to all servers mirc is connected to
Line 56: Line 56:
 
  ;If your knowledge about sockets is still [[$null]] or just not enough yet ;), maybe read this tutorial:
 
  ;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
 
  ; http://www.mircscripts.org/showdoc.php?type=tutorial&id=1128 or check /help Sockets
 
+
== See Also ==
[[Category:Script Archive]]
+
* [[Big sockets tutorial]]
 +
[[Category:Tutorials]][[Category:Socket]]

Latest revision as of 21:43, 10 June 2010

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 useful 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 *: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

See Also