getting data from a port in use

Grant Edwards grante at visi.com
Tue Feb 1 22:49:59 EST 2005


On 2005-02-02, Dana Marcusanu <dmarcusanu at 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/showfiles.php?group_id=14007&package_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?



More information about the Python-list mailing list