Re: socket programming...lsof?
- From: Eric Wong <normalperson@xxxxxxxx>
- Date: Sat, 3 Apr 2010 02:27:31 -0500
Derek Smith <derekbellnersmith@xxxxxxxxx> wrote:
env ruby -w
host = 'localhost'
port = 22
s = TCPSocket.open(host, port)
while line = s.gets # Read lines from the socket
puts line.chop # And print with platform line terminator
s.close # Close the socket when done
derek@vaio-ubuntu:~$ sudo ruby port_tst.rb
What if I want to see any data passing over that port, 113 or any other
port? Any adjustments in this code?
You should actually use something like tcpdump or some other sniffer.
See http://en.wikipedia.org/wiki/Tcpdump for more info.
Since tcpdump uses libpcap, and there are libpcap bindings for Ruby, so
you could probably do this via the Ruby bindings without much
difficulty (I've never tried this).
SSH port 22 seems to work, well sort of. When connections come in,
shouldn't I see some type of encryption strings?
No, not at all.
Your current code is opening a new and private connection to a TCP
server (sshd). This is just as if you're normally opening a new ssh
client connection to your server (without actually going through the
TCP connections are generally private (unicast). That is when a client
connects to a server, that connection is a bidirectional bytestream
only intended for the client and server to consume.
You need special OS-level tracing tools like libpcap (or knowledge
of obscure syscalls which libpcap uses) to listen into the private
server<->client channel as a 3rd party.
- Prev by Date: Re: Its a bird, its a plane, its.. um, an Attribute based System?
- Next by Date: Re: hash key with multiple values
- Previous by thread: Re: socket programming...lsof?
- Next by thread: Re: socket programming...lsof?