Skip to content

Instantly share code, notes, and snippets.

@rkotov93
Last active February 27, 2017 12:37
Show Gist options
  • Save rkotov93/96c689906ea32046dbe6e449dd0334ca to your computer and use it in GitHub Desktop.
Save rkotov93/96c689906ea32046dbe6e449dd0334ca to your computer and use it in GitHub Desktop.
require 'socket'
# read 1024 bytes from /dev/urandom and replace non UTF-8 cahracters with ''
seq = %x(dd if=/dev/urandom bs=1024 count=1)
seq.encode!('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
seq.gsub!(/\s+/, "")
# Send urandom data to the server via socket
socket = TCPSocket.open('localhost', 7563)
socket.print(seq)
socket.close
require 'socket'
server = TCPServer.new 'localhost', 7563
puts 'Listen to localhost:7563'
loop do
# Start socket connection handling in Thread
Thread.start(server.accept) do |client|
puts '-' * 50
puts "START SOCKET CONNECTION #{Time.now}"
puts '-' * 50
# Print request content to console
while line = client.gets
puts line
end
puts '-' * 50
puts "FINISH SOCKET CONNECTION #{Time.now}"
puts '-' * 50
client.close
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment