Py3flowtools
Python tools for working with netflow data
Install / Use
/learn @bbayles/Py3flowtoolsREADME
Introduction
This repository holds Python tools for reading NetFlow data. They are lightweight wrappers on top of the flow-tools and flowd binaries. They should be considered experimental.
These tools are written with Python 3 in mind, but I will keep them working with Python 2.7 as well.
I test the most with NetFlow v5. If you have samples of other NetFlow logs that you can share, please send them to me. As of 2015-08-01 I've been using nfdump for NetFlow v9.
Requirements
You will need:
- The
flow-toolspackage installed (get it from your distribution or from the source) and theflow-exportbinary on your path - The
flowdpackage installed (get it from your distribution or from the source) and theflowd-readerbinary on your path. - (Python 2.7 only) The
subprocess32module installed (get it from PyPi)
Usage
Call one of these functions to a NetFlow log to get an iterator over the flows in the log:
- Use
NetFlowLogto have the module try to guess which reader to use - Use
FlowToolsLogfor logs thatflow-toolscan read - Use
FlowdLogfor logs thatflowdcan reader
The iterator will return a data structure that exposes these attributes:
first- A naivedatetime.datetimeobject. UTC is assumed.last- A naivedatetime.datetimeobject. UTC is assumed.srcaddr- IP address as a stringsrcaddr_raw- IP address as an integerdstaddr- IP address as a stringdstaddr_raw- IP address as an integersrcport- Port number in decimaldstport- Port number in decimalprot- Protocol number in decimal, e.g.6for TCP and17for UDPdOctets- Number of octetsdPkts- Number of packetstcp_flags- Integer with the TCP flags
from py3flowtools import FlowToolsLog
parser = FlowToolsLog('flowtools.bin')
for line in parser:
print(line.dOctets, sep='\t')
TODO list
- More unit tests
- IPv6 support
- More thorough documentation
- Support for gzip-compressed logs
I started with the idea of updating the pyflowtools to support Python 3. However, I decided I wanted to use a more permissive license and develop more rapidly.
