getting data from a port in use

D

Dana Marcusanu

Hi to all,
I am trying to use Python to get the data received at a specific port (in
use) on my computer. I already tried below code which seems to hang at the
statement accepting connections. I don't know what else I can try. Any
suggestions will be welcome.

import socket, select, os

PORT = 2005
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((socket.gethostname(), PORT))
s.listen(1)
work_socket, addr = s.accept()
data = s.recv(1024)
print data
s.close()

Thank you, Dana



__________________________________
Do you Yahoo!?
Meet the all-new My Yahoo! - Try it today!
http://my.yahoo.com
 
G

Grant Edwards

I am trying to use Python to get the data received at a specific port (in
use) on my computer.

What do you mean "in use"? You mean you want to evesdropt on
data that's being sent to an existing connection? If so,
you'll need to use something like the pcap library.
I already tried below code which seems to hang at the
statement accepting connections. I don't know what else I can try. Any
suggestions will be welcome.

import socket, select, os

PORT = 2005
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((socket.gethostname(), PORT))
s.listen(1)
work_socket, addr = s.accept()
data = s.recv(1024)

No matter what you're trying to do, this isn't right. Once the
connection has been accepted, you have to read data from the
socket returned by the accept() call.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,840
Latest member
BrendanG78

Latest Threads

Top