Skip to content

Instantly share code, notes, and snippets.

@gucchan22
Created April 14, 2017 03:44
Show Gist options
  • Save gucchan22/bf3817c33b57425c9f1d1463fa682d2a to your computer and use it in GitHub Desktop.
Save gucchan22/bf3817c33b57425c9f1d1463fa682d2a to your computer and use it in GitHub Desktop.
#-*- coding:utf-8 -*-
require "socket"
def telnet_proc(cmd, isrc, idst)
begin
fmt = "#{Time.new}, #{isrc}, #{idst}, #{cmd.chomp!}"
`echo #{fmt} >> ~/Desktop/telnet_out.txt`
`echo '#{cmd}' | hexdump -C >> ~/Desktop/telnet_out.txt`
return "CONNECTION SUCCESS"
rescue
return "CONNECTION SUCCESS"
end
end
ts = TCPServer.open(23235)
# SYN(A) -> SYN+ACK(S) -> RST(A) / SYN+ACK or RST+ACK.
sock = ts.accept
while buf = sock.gets
puts telnet_proc(buf, sock.peeraddr[1], sock.peeraddr[2])
end
sock.close
ts.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment