Redirecting stdin/stdout to self
Grant Edwards
grante at visi.com
Mon Jan 23 14:39:00 EST 2006
On 2006-01-23, Grant Edwards <grante at visi.com> wrote:
> On 2006-01-23, Jan Danielsson <jan.danielsson at gmail.com> wrote:
>
>> And if I'm reading it correctly, the Perl
>> script's process starts tcpdump, but redirects its output to its own
>> input, and reads it line by line.
> [...]
>> ...however, the Perl script solution looks interresting.. Is it
>> possible to do something like that in Python?
>
> os.popen()
>
> http://www.python.org/doc/current/lib/os-process.html
I should have also added that there's a module that allows you
to call libpcap directly (libpcap is the library that tcpdump
uses to capture packets).
http://sourceforge.net/projects/pylibpcap/
It's way, way more efficient than parsing tcpdump's output. If
you're only grabbing a few packets it may not matter. For some
of the apps I've done, using pylibpcap has cut run-times by a
factor of 10 or more.
--
Grant Edwards grante Yow! Life is selling
at REVOLUTIONARY HAIR
visi.com PRODUCTS!
More information about the Python-list
mailing list