Skip to content

Instantly share code, notes, and snippets.

@ukoloff

ukoloff/nc.rb Secret

Created April 8, 2015 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ukoloff/e0fbf97fe2778f8e5514 to your computer and use it in GitHub Desktop.
Save ukoloff/e0fbf97fe2778f8e5514 to your computer and use it in GitHub Desktop.
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