root/mirror/edenwall/pynetfilter_conntrack/trunk/events.py

Revision 5895, 0.6 kB (checked in by haypo, 3 years ago)

Write ConntrackBase?._error() to factorize error code

  • Property svn:eol-style set to native
Line 
1#!/usr/bin/env python
2from pynetfilter_conntrack import (Conntrack, ConntrackEntry,
3    NFCT_ALL_CT_GROUPS,
4    NFCT_CB_STOP, NFCT_CB_CONTINUE)
5from socket import AF_INET
6
7counter = 0
8
9def event_cb(msgtype, ct, data):
10    global counter
11    counter += 1
12    if 10 <= counter:
13        return NFCT_CB_STOP
14
15    entry = ConntrackEntry(data, ct, msgtype, destroy=False)
16    print entry
17
18    return NFCT_CB_CONTINUE
19
20def main():
21    conntrack = Conntrack(subscriptions=NFCT_ALL_CT_GROUPS)
22    event_cb.conntrack = conntrack
23    try:
24        conntrack.catch(event_cb)
25    except KeyboardInterrupt:
26        print "Interrupted."
27
28main()
Note: See TracBrowser for help on using the browser.