Gopi Gopi - 3 months ago 20
Python Question

how to use pynetfilter_conntrack library of python

I am trying to write a python program for listing established TCP connections. I found pynetfilter_conntrack module. I have installed using

pip install pynetfilter_conntrack
. while importing the library I got error as below

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pynetfilter_conntrack/", line 4, in <module>
from pynetfilter_conntrack.func import *
File "/usr/local/lib/python2.7/dist-packages/pynetfilter_conntrack/", line 6, in <module>
library = cdll.LoadLibrary("")
File "/usr/lib/python2.7/ctypes/", line 443, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python2.7/ctypes/", line 365, in __init__
self._handle = _dlopen(self._name, mode)
OSError: cannot open shared object file: No such file or directory

And fixed using command

sudo ln -s /usr/lib/ /usr/lib/

I searched, but I could not get document on how to use it with some example program. Also it's wiki site is currently down.


Web page is down due the finishing of sponsored development. But there is a new maintainer on github trying to prevent the final death of the library.

As I see this repo (0.5) version is currently in development, but got an a example which will give you the key idea of using even 0.4.2 version.

from netifaces AF_INET
import pynetfilter_conntrack

# Print source ip, port and sent bytes
ct = pynetfilter_conntrack.Conntrack()
for item in ct.dump_table(AF_INET):
    print item.orig_ipv4_src, item.orig_port_src, item.repl_counter_bytes