Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to achieve tcpflow functionality (follow tcp stream) purely within python
    primarykey
    data
    text
    <p>I am writing a tool in python (platform is linux), one of the tasks is to capture a live tcp stream and to apply a function to each line. Currently I'm using</p> <pre><code>import subprocess proc = subprocess.Popen(['sudo','tcpflow', '-C', '-i', interface, '-p', 'src', 'host', ip],stdout=subprocess.PIPE) for line in iter(proc.stdout.readline,''): do_something(line) </code></pre> <p>This works quite well (with the appropriate entry in /etc/sudoers), but I would like to avoid calling an external program.</p> <p>So far I have looked into the following possibilities: </p> <ul> <li><p><a href="http://monkey.org/~jose/software/flowgrep/" rel="nofollow noreferrer">flowgrep</a>: a python tool which looks just like what I need, BUT: it uses <a href="http://pilcrow.madison.wi.us/pynids/" rel="nofollow noreferrer">pynids</a> internally, which is 7 years old and seems pretty much abandoned. There is no pynids package for my gentoo system and it ships with a patched version of libnids which I couldn't compile without further tweaking.</p></li> <li><p><a href="http://www.secdev.org/projects/scapy/" rel="nofollow noreferrer">scapy</a>: this is a package manipulation program/library for python, I'm not sure if tcp stream reassembly is supported.</p></li> <li><p><a href="http://code.google.com/p/pypcap/" rel="nofollow noreferrer">pypcap</a> or <a href="http://sourceforge.net/projects/pylibpcap/" rel="nofollow noreferrer">pylibpcap</a> as wrappers for libpcap. Again, libpcap is for packet capturing, where I need stream reassembly which is not possible according to <a href="https://stackoverflow.com/questions/600087/can-libpcap-reassemble-tcp-segments">this question</a>.</p></li> </ul> <p>Before I dive deeper into any of these libraries I would like to know if maybe someone has a working code snippet (this seems like a rather common problem). I'm also grateful if someone can give advice about the right way to go.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload