469,645 Members | 1,105 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

getting data from a port in use

Yes. I want to write a very small web sniffer that gets data from a
specified port. I already looked at some of the existing ones on Internet,
but they are not in Python (I am trying to learn Python!) and they have a
lot more features that I want. Thanks for your suggestion. I will check
out pcap library.

Dana

On 2005-02-01, Dana Marcusanu <dmarcus...@yahoo.com> wrote:
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.
print data
s.close()


--
Grant Edwards grante Yow! Actually, what
at I'd like is a little
toy
visi.com spaceship!!

__________________________________
Do you Yahoo!?
Yahoo! Mail - 250MB free storage. Do more. Manage less.
http://info.mail.yahoo.com/mail_250
Jul 18 '05 #1
1 2003
On 2005-02-02, Dana Marcusanu <dm********@yahoo.com> wrote:
Yes. I want to write a very small web sniffer that gets data
from a specified port.
OK, know we know what you're actually trying to do. You should
have told us that to start with rather than leading us down the
wrong path with your little Python program. When asking for
help, always clearly describe your _problem_ first. Asking
what's wrong with a proposed solution without clearly
describing the problem you're trying to solve just wastes time:

http://www.catb.org/~esr/faqs/smart-questions.html
I already looked at some of the existing ones on Internet, but
they are not in Python (I am trying to learn Python!)
You picked a rather tricky little project.
and they have a lot more features that I want. Thanks for your
suggestion. I will check out pcap library.


Pcap is your only hope unless you want to do a lot of rather
nasty low level stuff (for which you'll probably have to write
a bunch of C code that does all the things that libpcap does).

You can't use the normal Python socket API to sniff data.

You _could_ use popen to run tcpdump (which in turn uses pcap)
and then parse the output from pcap. I've done both, and IMO
using pcap directly is a lot easier. It's also your only hope
of keeping up with any amount of traffic.

http://sourceforge.net/projects/pylibpcap
http://sourceforge.net/project/showf...ckage_id=13826

Once upon a time, there was a rumor that somebody had a Win32
version of pylibpcap.

Good luck. :)

--
Grant Edwards grante Yow! Did an Italian CRANE
at OPERATOR just experience
visi.com uninhibited sensations in
a MALIBU HOT TUB?
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Dana Marcusanu | last post: by
reply views Thread by Stefan Tietke | last post: by
reply views Thread by mmcgee00 | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.