Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;;mIRC Telnet v1.0 by stefys
- ;;;This program helps you connecting to servers (tcp or udp) and for listening ports (tcp or udp)
- ;;;All you have to do is to type /telnet and then type the command "help"
- alias telnet { var %i = 1 | while ($window(@telnet $+ %i)) { inc %i } | var %w = @telnet $+ %i | window -aek0 %w | .timer 1 0 editbox %w > }
- alias base2hex {
- var %i = 1
- while ($mid($1-,%i,1) != $null) {
- var %b = $asc($ifmatch)
- var %c = $base(%b,10,16)
- if ($len(%c) == 1) %c = 0 $+ %c
- if (%b == 32) var %str = %str $+ %c $chr(32)
- else var %str = %str $+ %c $chr(32)
- inc %i
- }
- return %str
- }
- alias socki {
- var %on = $1
- var %of = $2
- aline -ph %on 4* Socket type: $sock(%of).type $+
- aline -ph %on 4* Socket status: $sock(%of).status $+
- if ($sock(%of).status == listening) {
- aline -ph %on 4* Bind ip: $sock(%of).bindip $+
- aline -ph %on 4* Bind port: $sock(%of).bindport $+
- }
- aline -ph %on 4* Sent data: $getk($sock(%of).sent) KB
- aline -ph %on 4* Received data: $getk($sock(%of).rcvd) KB
- aline -ph %on 4* Last send message: $duration($sock(%of).ls) ago
- aline -ph %on 4* Last read message: $duration($sock(%of).lr) ago
- aline -ph %on 4* Open time: $duration($sock(%of).to) ago
- aline -ph %on 4 $+ $str(-,32) $+
- }
- alias getk {
- var %a = $calc($1 / 1024)
- if (. !isin %a) return %a
- else return $gettok(%a,1,$asc(.)) $+ . $+ $mid($gettok(%a,2,$asc(.)),1,3)
- }
- on 1:keydown:@telnet*:*:{
- if ($left($editbox($active),1) != >) editbox $active >
- }
- on 1:sockopen:@telnet*:{
- if ($sockerr) && ($window($sockname)) aline -ph $sockname 4* Error connecting to $sock($sockname).ip $+ : $+ $sock($sockname).port $+
- elseif ($window($sockname)) aline -ph $sockname 4* Connected.
- }
- on 1:sockread:@telnet*:{
- if (!$hget($sockname,hex)) {
- var %data
- sockread %data
- if ($window($sockname)) { if (%data) noop $dll(spaces.dll, echo, -h $sockname %data) | else aline -ph $sockname $chr(160) }
- }
- else {
- sockread &data
- var %i = 0
- var %max = 16
- while ($bvar(&data,$iif(!$calc(%i * %max),1,$calc(%i * 16)),$calc((%i + 1) * %max))) {
- var %t = $ifmatch, %t2 = $null, %x = 1
- while ($gettok(%t,%x,32)) {
- var %a = $base($ifmatch,10,16)
- var %t2 = %t2 $iif($len(%a) == 2,%a,0 $+ %a)
- inc %x
- }
- if ($window($sockname)) { if (%t2} aline -ph $sockname %t2 | else aline -ph $sockname $chr(160) }
- inc %i
- }
- }
- }
- on 1:sockclose:@telnet*:{
- if ($window($sockname)) aline -ph $sockname 4* The remote host closed the connection.
- if ($hget($sockname)) hfree $sockname
- }
- on 1:socklisten:@telnet*:{
- inc -u3 $+(%,fldsocks.,$sockname) 1
- if ($+(%,fldsocks.,$sockname) > 3) && ($hget($sockname,prot)) {
- var %sn = refused $+ $r(1000,9999)
- sockaccept %sn
- if ($window($sockname)) aline -ph $sockname 4* Attemping to connect from $sock(%sn).ip (refused because of anti-flood reasons)
- sockclose %sn
- }
- else {
- var %i = 1
- while ($window($sockname $+ - $+ %i)) { inc %i }
- var %sn = $sockname $+ - $+ %i
- sockaccept %sn
- window -aek0 %sn
- if ($window($sockname)) aline -ph $sockname 4* Attemping to connect from $sock(%sn).ip on %sn (accepted).
- aline -ph %sn 4* Connection from $sock(%sn).ip accepted.
- hadd -m %sn hex $hget($sockname,hex)
- }
- }
- on 1:udpread:@telnet*:{
- var %data
- sockread %data
- if ($hget($sockname,hex)) %data = $base2hex(%data)
- if ($window($sockname)) aline -ph $sockname $chr(91) $+ $sock($sockname).ip $+ $chr(93) %data
- }
- on 1:input:@telnet*:{
- if ($left($1,1) == >) {
- tokenize 32 $mid($1-,2)
- if ($1 == connect) {
- if ($numtok($2-,32) == 3) && ($regex($2,/^-([uh]+)$/)) {
- var %switch = $regml(1)
- var %serv = $3
- var %port = $4
- }
- else { var %serv = $2 | var %port = $3 }
- if (u isincs %switch) var %proto = udp
- else var %proto = tcp
- if (h isincs %switch) hadd -m $active hex 1
- else hadd -m $active hex 0
- if ($sock($active)) echo 4 -a * This session is already used.
- elseif (!%serv) || (!%port) echo 4 -a * Syntax: >connect [-uh] <serv> <port>
- elseif (%proto == tcp) { sockopen $active %serv %port | echo 4 -a * Connecting to %serv $+ : $+ %port }
- elseif (%proto == udp) { echo 4 -a * Set %serv $+ : $+ %port as udp server. | hadd -m $active udpserv %serv | hadd -m $active udpport %port }
- }
- elseif ($1 == listen) {
- if ($numtok($2-,32) == 2) && ($regex($2,/^-([uh]+)$/)) {
- var %switch = $regml(1)
- var %port = $3
- }
- else var %port = $2
- if (u isincs %switch) var %proto = udp
- else var %proto = tcp
- if (h isincs %switch) hadd -m $active hex 1
- else hadd -m $active hex 0
- if (f isincs %switch) hadd -m $active prot 1
- else hadd -m $active prot 0
- if ($sock($active)) echo 4 -a * This session is already used.
- elseif (!%port) echo 4 -a * Syntax: >listen [-uh] <port>
- elseif (!$portfree(%port)) aline -ph $active 4* Port in use.
- 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 }
- elseif (%proto == tcp) { socklisten $active %port | aline -ph $active 4* Now listening to port %port (tcp) }
- }
- elseif ($1 == conns) {
- if ($sock($active).status != listening) aline -ph $active 4* This is not a listening session.
- elseif ($sock($active $+ *-*,0) == 0) aline -ph $active 4* No opened connections.
- else {
- var %i = 1
- while ($sock($active $+ *-*,%i)) {
- var %a = $ifmatch
- aline -ph $active 4* Window: %a $+
- socki $active %a
- inc %i
- }
- }
- }
- elseif ($1 == kill) {
- if (!$2) var %w = $active
- else var %w = @ $+ $2
- sockclose %w
- if ($window(%w)) window -c %w
- }
- 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 } }
- elseif ($1 == help) {
- aline -ph $active 4* >connect [-uh] <server> <port>
- aline -ph $active $str($chr(160),4) $+ Let's you connect to servers.
- aline -ph $active $str($chr(160),4) $+ -u switch means you want to connect to server via udp (instead of tcp)
- aline -ph $active $str($chr(160),4) $+ -h switch means the read data from the server is shown as hex (base 16)
- aline -ph $active 4* >listen [-uhf] <port>
- aline -ph $active $str($chr(160),4) $+ Let's you listen to ports.
- aline -ph $active $str($chr(160),4) $+ -u switch means you want to listen to udp (instead of tcp)
- aline -ph $active $str($chr(160),4) $+ -h switch means the read data is shown as hex (base 16)
- 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)
- aline -ph $active 4* >exit
- aline -ph $active $str($chr(160),4) $+ Close connection with server.
- aline -ph $active 4* >conns
- aline -ph $active $str($chr(160),4) $+ View connections opened by the listening port (working only for tcp)
- aline -ph $active 4* >kill [window]
- 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)
- aline -ph $active 4* >state
- aline -ph $active $str($chr(160),4) $+ View the state of the current connection.
- aline -ph $active 4* >new
- aline -ph $active $str($chr(160),4) $+ Opens a new telnet window.
- aline -ph $active 4* >clear
- aline -ph $active $str($chr(160),4) $+ Clears this screen.
- aline -ph $active 4* >help
- aline -ph $active $str($chr(160),4) $+ Show this help.
- aline -ph $active 4 $+ $str(-,32) $+
- }
- elseif ($1 == new) telnet
- elseif ($1 == state) {
- if ($sock($active)) {
- socki $active $active
- }
- else aline -ph $active 4* Not connected.
- }
- elseif ($1 == clear) clear
- else {
- if ((!$sock($active)) && (!$hget($active,udpserv))) || ($sock($active).status == listening) echo 4 -a * Not connected to server.
- else {
- if ($sock($active).type == tcp) sockwrite -n $active $1-
- else sockudp -n $active $hget($active,udpserv) $hget($active,udpport) $1-
- if ($hget($active,hex)) aline -ph $active 4> $base2hex($1- $+ $crlf)
- else aline -ph $active 4> $1-
- }
- }
- editbox $active >
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement