-
-
Save ukoloff/e0fbf97fe2778f8e5514 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'Socket' | |
class NetCat | |
Chunk=0x10000 | |
def self.run! | |
STDOUT.sync=true | |
STDIN.binmode | |
STDOUT.binmode | |
new | |
end | |
def initialize | |
@t1=Thread.new{sloop} | |
@t1.join | |
end | |
def cloop | |
begin | |
until STDIN.eof | |
@client.write STDIN.readpartial Chunk | |
end | |
rescue=>e | |
ensure | |
@t1.exit | |
end | |
end | |
def sloop | |
begin | |
@client=@server=Socket.tcp 'ekb.ru', 22 | |
@t2=Thread.new{cloop} | |
until @client.eof | |
STDOUT.write @client.readpartial Chunk | |
end | |
rescue=>e | |
ensure | |
@client.close if @client | |
@t2.exit if @t2 | |
end | |
end | |
run! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment