Advertisement
Guest User

telnet script

a guest
Apr 17th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 8.65 KB | None | 0 0
  1. ;;;mIRC Telnet v1.0 by stefys
  2. ;;;This program helps you connecting to servers (tcp or udp) and for listening ports (tcp or udp)
  3. ;;;All you have to do is to type /telnet and then type the command "help"
  4.  
  5.  
  6. alias telnet { var %i = 1 | while ($window(@telnet $+ %i)) { inc %i } | var %w = @telnet $+ %i | window -aek0 %w | .timer 1 0 editbox %w > }
  7. alias base2hex {
  8.   var %i = 1
  9.   while ($mid($1-,%i,1) != $null) {
  10.     var %b = $asc($ifmatch)
  11.     var %c = $base(%b,10,16)
  12.     if ($len(%c) == 1) %c = 0 $+ %c
  13.     if (%b == 32) var %str = %str $+ %c $chr(32)
  14.     else var %str = %str $+ %c $chr(32)
  15.     inc %i
  16.   }
  17.   return %str
  18. }
  19. alias socki {
  20.   var %on = $1
  21.   var %of = $2
  22.   aline -ph %on 4* Socket type: $sock(%of).type $+ 
  23.   aline -ph %on 4* Socket status: $sock(%of).status $+ 
  24.   if ($sock(%of).status == listening) {
  25.     aline -ph %on 4* Bind ip: $sock(%of).bindip $+ 
  26.     aline -ph %on 4* Bind port: $sock(%of).bindport $+ 
  27.   }
  28.   aline -ph %on 4* Sent data: $getk($sock(%of).sent) KB
  29.   aline -ph %on 4* Received data: $getk($sock(%of).rcvd) KB
  30.   aline -ph %on 4* Last send message: $duration($sock(%of).ls) ago
  31.   aline -ph %on 4* Last read message: $duration($sock(%of).lr) ago
  32.   aline -ph %on 4* Open time: $duration($sock(%of).to) ago
  33.   aline -ph %on 4 $+ $str(-,32) $+ 
  34. }
  35. alias getk {
  36.   var %a = $calc($1 / 1024)
  37.   if (. !isin %a) return %a
  38.   else return $gettok(%a,1,$asc(.)) $+ . $+ $mid($gettok(%a,2,$asc(.)),1,3)
  39. }
  40. on 1:keydown:@telnet*:*:{
  41.   if ($left($editbox($active),1) != >) editbox $active >
  42. }
  43. on 1:sockopen:@telnet*:{
  44.   if ($sockerr) && ($window($sockname)) aline -ph $sockname 4* Error connecting to $sock($sockname).ip $+ : $+ $sock($sockname).port $+ 
  45.   elseif ($window($sockname)) aline -ph $sockname 4* Connected.
  46. }
  47. on 1:sockread:@telnet*:{
  48.   if (!$hget($sockname,hex)) {
  49.     var %data
  50.     sockread %data
  51.     if ($window($sockname)) { if (%data) noop $dll(spaces.dll, echo, -h $sockname %data) | else aline -ph $sockname $chr(160) }
  52.   }
  53.   else {
  54.     sockread &data
  55.     var %i = 0
  56.     var %max = 16
  57.     while ($bvar(&data,$iif(!$calc(%i * %max),1,$calc(%i * 16)),$calc((%i + 1) * %max))) {
  58.       var %t = $ifmatch, %t2 = $null, %x = 1
  59.       while ($gettok(%t,%x,32)) {
  60.         var %a = $base($ifmatch,10,16)
  61.         var %t2 = %t2 $iif($len(%a) == 2,%a,0 $+ %a)
  62.         inc %x
  63.       }
  64.       if ($window($sockname)) { if (%t2} aline -ph $sockname %t2 | else aline -ph $sockname $chr(160) }
  65.       inc %i
  66.     }
  67.   }
  68. }
  69. on 1:sockclose:@telnet*:{
  70.   if ($window($sockname)) aline -ph $sockname 4* The remote host closed the connection.
  71.   if ($hget($sockname)) hfree $sockname
  72. }
  73.  
  74. on 1:socklisten:@telnet*:{
  75.   inc -u3 $+(%,fldsocks.,$sockname) 1
  76.   if ($+(%,fldsocks.,$sockname) > 3) && ($hget($sockname,prot)) {
  77.     var %sn = refused $+ $r(1000,9999)
  78.     sockaccept %sn
  79.     if ($window($sockname)) aline -ph $sockname 4* Attemping to connect from $sock(%sn).ip (refused because of anti-flood reasons)
  80.     sockclose %sn
  81.   }
  82.   else {
  83.     var %i = 1
  84.     while ($window($sockname $+ - $+ %i)) { inc %i }
  85.     var %sn = $sockname $+ - $+ %i
  86.     sockaccept %sn
  87.     window -aek0 %sn
  88.     if ($window($sockname)) aline -ph $sockname 4* Attemping to connect from $sock(%sn).ip on %sn (accepted).
  89.     aline -ph %sn 4* Connection from $sock(%sn).ip accepted.
  90.     hadd -m %sn hex $hget($sockname,hex)
  91.   }
  92. }
  93.  
  94. on 1:udpread:@telnet*:{
  95.   var %data
  96.   sockread %data
  97.   if ($hget($sockname,hex)) %data = $base2hex(%data)
  98.   if ($window($sockname)) aline -ph $sockname $chr(91) $+ $sock($sockname).ip $+ $chr(93) %data
  99. }
  100.  
  101. on 1:input:@telnet*:{
  102.   if ($left($1,1) == >) {
  103.     tokenize 32 $mid($1-,2)
  104.     if ($1 == connect) {
  105.       if ($numtok($2-,32) == 3) && ($regex($2,/^-([uh]+)$/)) {
  106.         var %switch = $regml(1)
  107.         var %serv = $3
  108.         var %port = $4
  109.       }
  110.       else { var %serv = $2 | var %port = $3 }
  111.       if (u isincs %switch) var %proto = udp
  112.       else var %proto = tcp
  113.       if (h isincs %switch) hadd -m $active hex 1
  114.       else hadd -m $active hex 0
  115.       if ($sock($active)) echo 4 -a * This session is already used.
  116.       elseif (!%serv) || (!%port) echo 4 -a * Syntax: >connect [-uh] <serv> <port>
  117.       elseif (%proto == tcp) { sockopen $active %serv %port | echo 4 -a * Connecting to %serv $+ : $+ %port }
  118.       elseif (%proto == udp) { echo 4 -a * Set %serv $+ : $+ %port as udp server. | hadd -m $active udpserv %serv | hadd -m $active udpport %port }
  119.     }
  120.     elseif ($1 == listen) {
  121.       if ($numtok($2-,32) == 2) && ($regex($2,/^-([uh]+)$/)) {
  122.         var %switch = $regml(1)
  123.         var %port = $3
  124.       }
  125.       else var %port = $2
  126.       if (u isincs %switch) var %proto = udp
  127.       else var %proto = tcp
  128.       if (h isincs %switch) hadd -m $active hex 1
  129.       else hadd -m $active hex 0
  130.       if (f isincs %switch) hadd -m $active prot 1
  131.       else hadd -m $active prot 0
  132.       if ($sock($active)) echo 4 -a * This session is already used.
  133.       elseif (!%port) echo 4 -a * Syntax: >listen [-uh] <port>
  134.       elseif (!$portfree(%port)) aline -ph $active 4* Port in use.
  135.       elseif (%proto == udp) { sockudp -k $active %port | aline -ph $active 4* Now listening to port %port (udp) | hadd -m $active udpserv 127.0.0.1 | hadd -m $active udpport %port }
  136.       elseif (%proto == tcp) { socklisten $active %port | aline -ph $active 4* Now listening to port %port (tcp) }
  137.     }
  138.     elseif ($1 == conns) {
  139.       if ($sock($active).status != listening) aline -ph $active 4* This is not a listening session.
  140.       elseif ($sock($active $+ *-*,0) == 0) aline -ph $active 4* No opened connections.
  141.       else {
  142.         var %i = 1
  143.         while ($sock($active $+ *-*,%i)) {
  144.           var %a = $ifmatch
  145.           aline -ph $active 4* Window: %a $+ 
  146.           socki $active %a
  147.           inc %i
  148.         }
  149.       }
  150.     }
  151.     elseif ($1 == kill) {
  152.       if (!$2) var %w = $active
  153.       else var %w = @ $+ $2
  154.       sockclose %w
  155.       if ($window(%w)) window -c %w
  156.     }
  157.     elseif ($1 == exit) { if (!$sock($active)) && (!$hget($active,udpserv)) echo 4 -a * Not connected to server. | else { sockclose $active | if ($hget($active)) hfree $active | echo 4 -a * Disconnected. | if (- isin $active) window -c $active } }
  158.     elseif ($1 == help) {
  159.       aline -ph $active 4* >connect [-uh] <server> <port>
  160.       aline -ph $active $str($chr(160),4) $+ Let's you connect to servers.
  161.       aline -ph $active $str($chr(160),4) $+ -u switch means you want to connect to server via udp (instead of tcp)
  162.       aline -ph $active $str($chr(160),4) $+ -h switch means the read data from the server is shown as hex (base 16)
  163.       aline -ph $active 4* >listen [-uhf] <port>
  164.       aline -ph $active $str($chr(160),4) $+ Let's you listen to ports.
  165.       aline -ph $active $str($chr(160),4) $+ -u switch means you want to listen to udp (instead of tcp)
  166.       aline -ph $active $str($chr(160),4) $+ -h switch means the read data is shown as hex (base 16)
  167.       aline -ph $active $str($chr(160),4) $+ -f switch means flood protection (it will refuse connections if there are more than 3 in 3 seconds)
  168.       aline -ph $active 4* >exit
  169.       aline -ph $active $str($chr(160),4) $+ Close connection with server.
  170.       aline -ph $active 4* >conns
  171.       aline -ph $active $str($chr(160),4) $+ View connections opened by the listening port (working only for tcp)
  172.       aline -ph $active 4* >kill [window]
  173.       aline -ph $active $str($chr(160),4) $+ Closes the connection of window and closes the window (if window is not specified, it's assumed the current window)
  174.       aline -ph $active 4* >state
  175.       aline -ph $active $str($chr(160),4) $+ View the state of the current connection.
  176.       aline -ph $active 4* >new
  177.       aline -ph $active $str($chr(160),4) $+ Opens a new telnet window.
  178.       aline -ph $active 4* >clear
  179.       aline -ph $active $str($chr(160),4) $+ Clears this screen.
  180.       aline -ph $active 4* >help
  181.       aline -ph $active $str($chr(160),4) $+ Show this help.
  182.       aline -ph $active 4 $+ $str(-,32) $+ 
  183.     }
  184.     elseif ($1 == new) telnet
  185.     elseif ($1 == state) {
  186.       if ($sock($active)) {
  187.         socki $active $active
  188.       }
  189.       else aline -ph $active 4* Not connected.
  190.     }
  191.     elseif ($1 == clear) clear
  192.     else {
  193.       if ((!$sock($active)) && (!$hget($active,udpserv))) || ($sock($active).status == listening) echo 4 -a * Not connected to server.
  194.       else {
  195.         if ($sock($active).type == tcp) sockwrite -n $active $1-
  196.         else sockudp -n $active $hget($active,udpserv) $hget($active,udpport) $1-
  197.         if ($hget($active,hex)) aline -ph $active 4> $base2hex($1- $+ $crlf)
  198.         else aline -ph $active 4> $1-
  199.       }
  200.     }
  201.     editbox $active >
  202.   }
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement