-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Mark Weiman edited this page Nov 9, 2018
·
2 revisions
python-flowtuple is a Python 3 module that grants access to the libflowtuple C library within Python.
This wiki is to help get familiar with python-flowtuple and how to use the module.
To build you will need Python 3.x (2.x or below will NOT work) and libflowtuple installed as well as git.
$ git clone https://github.com/Merit-Research/python-flowtuple.git
$ cd python-flowtuple
$ python3 setup.py build
# python3 setup.py install
To use the module, you just need to import the flowtuple
module in your
program.
Here is an example program to open a flowtuple file and get the interval times:
from sys import argv
# import flowtuple module
import flowtuple
# create flowtuple.Handle object
handle = flowtuple.Handle(argv[1])
print("Intervals in file %s:" % (argv[1],))
# tracker for whether interval is start or not
is_start = True
# get first record
record = handle.get_next()
# keep looping until record is None
while record is not None:
# is this an Interval?
if isinstance(record, flowtuple.Interval):
# is this the start of an Interval?
if is_start:
print("Start: %s; " % (record.time,), end='')
is_start = False
else:
print("End: %s" % (record.time,))
is_start = True
# get next record
record = handle.get_next()
Example output from above program:
$ python3 program.py flowtuple.gz
Intervals in file flowtuple.gz:
Start: 1539709003; End: 1539709062
Start: 1539709063; End: 1539709122
Start: 1539709123; End: 1539709182
Start: 1539709183; End: 1539709242
Start: 1539709243; End: 1539709302
Start: 1539709303; End: 1539709362
Start: 1539709363; End: 1539709422
Start: 1539709423; End: 1539709482
Start: 1539709483; End: 1539709542
Start: 1539709543; End: 1539709602
Start: 1539709603; End: 1539709662
Start: 1539709663; End: 1539709674
Take a look at Getting Started for more more detailed information on how to use this module.