tcpflow(1)
β¨ tcpflow(1) β¨
tcpflow 1.6.2 β bestie, this is a manual page, and it's about to be your new fave
π NAME π
tcpflow β TCP flow recorder
π¦ SYNOPSIS π¦
tcpflow [-aBcCDIpsZ] [-b max_bytes] [-d debug_level] [-[eE] scanner]
[-f max_fds] [-F[ctTXMkmg]] [-h|--help] [-i iface]
[-l file1.pcap file2.pcap...] [-L semlock] [-m min_bytes] [-o outdir]
[-r file1.pcap] [-R file0.pcap] [-S name=value] [-T[filename template]]
[-U|--relinquish-privileges username] [-v|--verbose] [-V|--version]
[-w file] [-x scanner] [-X file.xml] [-z|--chroot directory]
[expression]
πΈ DESCRIPTION πΈ
tcpflow is that girl. She captures the data that gets sent around inside TCP connections (aka flows), and she stores it in a way that's actually convenient for protocol analysis or debugging. No cap.
Here's the thing: instead of making you stare at packet-by-packet info like some kind of gremlin, tcpflow reconstructs the actual data streams and drops each flow into its own separate file so you can go back and look at it later. She understands TCP sequence numbers, so she'll rebuild the streams correctly no matter how many retransmissions or out-of-order deliveries the network throws at her. She ate, honestly.
She also gives you control over filenames for automatic binning of connections β by protocol, by IP address, or by connection number β and she has a sophisticated plug-in system for:
- decompressing compressed HTTP connections
- undoing MIME encoding
- calling user-provided programs for post-processing
By default, tcpflow stores all captured data in files with names that look like this:
192.168.101.102.02345-010.011.012.013.45103
...and the contents of that file would be the data transmitted from host 192.168.101.102 port 2345, to host 10.11.12.13 port 45103. The way that works is genuinely so satisfying once it clicks π
If you just wanna process a few hundred thousand packets and see what you've got, bestie, try this:
tcpflow -a -o outdir -Fk -r packets.pcap
That tells tcpflow to do -a (all processing), store the output in a directory called outdir, bin the output into directories of 1000 connections each, and read its input from the file packets.pcap. More sophisticated processing is possible, of course. We're just getting started π₯
β¨ OPTIONS β¨
-aβ Enable all processing. Same as-e all.-Bβ Force binary output even when printing to console with-Cor-c.-b max_bytesβ Specifies the maximum size of a captured flow. Any bytes beyondmax_bytesfrom the first byte captured will be discarded. The default is to store an unlimited number of bytes per flow.
Note: before version 1.4, tcpflow could only store a maximum of 4GiB per flow. Ancient history, but ok π
-cβ Console print. Print the contents of packets to stdout as they are received, without storing any captured data to files (implies-s).-Cβ Console print without the packet source and destination details being printed. Print the contents of packets to stdout as they are received, without storing any captured data to files (implies-s).-Dβ Console output should be in hex.-dβ Debug level. Set the level of debugging messages printed to stderr to debug_level. Higher numbers produce more messages.-d 0causes completely silent operation.-d 1, the default, produces minimal status messages.-d 10produces verbose output equivalent to-v.- Numbers higher than
10can produce a large amount of debugging information useful only to developers. (iykyk)
-E nameβ Disable all scanners and then enable scanner name.-e nameβ Enable scanner name.-e allβ Enables all scanners. Same as-a.-e httpβ Perform HTTP post-processing ("After" processing). If the output file is
208.111.153.175.00080-192.168.001.064.37314,
Then the post-processing will create the files:
208.111.153.175.00080-192.168.001.064.37314-HTTP
208.111.153.175.00080-192.168.001.064.37314-HTTPBODY
If the HTTPBODY was compressed with GZIP, you may get a third file as well:
208.111.153.175.00080-192.168.001.064.37314-HTTPBODY-GZIP
Additional information about these streams, such as their MD5 hash value, is also written to the DFXML report file.
-e python -S py_path=path -S py_module=module -S py_function=fooβ Post-process TCP payload by an external python function.
The python function must take a single string parameter. The python function can return a string (else the function does must not return). The returned string (if any) is written in the DFXML report file inside the XML tag <scan_python_result>...</scan_python_result>. A sample python script is available within the tcpflow source code in directory python/plugins.
Example:
tcpflow -r my.cap -e python -S py_path=python/plugins -S py_module=samplePlugin -S py_function=sampleFunction
-F[format]β Specifies format for output filenames.
Format specifiers:
cβ Appends the connection counter to ALL filenames.tβ Prepends each filename with a Unix timestamp (seconds since epoch).Tβ Prepends each filename with an ISO-8601 timestamp.Xβ Do not output any files (other than the DFXML report file).
-FMβ Include MD5 of each flow in the DFXML report file.-FXβ Suppresses file output entirely, DFXML report file is still produced.-Fkβ bin output in 1K directories-Fmβ bin output in 1M directories (2 levels)-Fgβ bin output in 1G directories (3 levels)-fmax_fdsβ Max file descriptors used. Limit the number of file descriptors used by tcpflow to max_fds. Higher numbers use more system resources, but usually perform better. If the underlying operating system supports thesetrlimit()system call, the OS will be asked to enforce the requested limit. The default is for tcpflow to use the maximum number of file descriptors allowed by the OS. The-voption will report how many file descriptors tcpflow is using.-gβ Output flow information to console in multiple colors. (Blue for client to server flows, red for server to client flows, green for undecided flows.) aesthetic
Note: This option was different from tcpflow 1.3 (-e) and 1.4.4 (-J).
-h --helpβ Help. Print usage information and exit.-hhβ More help. Print more usage information and exit. (yes bestie, you can stack them π«Ά)-i ifaceβ Interface name. Capture packets from the network interface named iface. If no interface is specified with-i, a reasonable default will be used bylibpcapautomatically.-Iβ Store the reception timestamps (of TCP packets) in a companion file*.findx. Therefore each flow will have two files:- the usual file containing payload bytes, and
- the text file containing the corresponding timestamps.
This last file *.findx has three columns using the pipe '|' as separator:
byte-index|timestamp|length
The byte-index column is the postion within the file containing the payload bytes. The timestamp column represents the number of seconds since epoch as a floating point number. The precision is the microsecond but may also be the nanosecond in a future tcpflow version. The length column is the number of successive bytes concerned by timestamp and can include several TCP frames (TCP packets). The extension findx may become from the fact that the timestamps are frame indexed.
-L semlock_nameβ Specifies that semlock_name should be used as a Unix semaphore to prevent two different copies of tcpflow running in two different processes but outputting to the same standard output from printing on top of each other. This is an application of Unix named semaphores; bet you have never seen one before. π-lβ Treat the following arguments as filenames with an assumed-rcommand before each one. This allows you to read a lot of files at once with shell globbing. For example, to process all of the pcap files in the current directory, use this:
tcpflow -o out -a -l *.pcap
-m min_sizeβ Forces a new connection output file when there is a skip in the TCP session of min_size bytes or more.-o outdirβ Specifies the output directory where the transcript files will be written.-Pβ No purge. Normally tcpflow removes connections from the hash table after the connection is closed with a FIN. This conserves memory but takes additional CPU time. Selecting this option causes thestd::tr1:unordered_mapto grow without bounds, as tcpflow did prior to version 1.1. That makes tcpflow run faster if there are less than 10 million connections, but can lead to out-of-memory errors.-pβ No promiscuous mode. Normally, tcpflow attempts to put the network interface into promiscuous mode before capturing packets. The-poption tells tcpflow not to put the interface into promiscuous mode. Note that it might already be in promiscuous mode for some other reason.-qβ Quiet mode --- don't print warnings. Currently the only warning that tcpflow prints is a warning when more than 10,000 files are created that the user should have provided the-Fk,-Fm, or-Fgoptions. We might have other warnings in the future.--relinquish-privileges=usernameβ When tcpflow is run as root, this option changes the user ID and group ID to write files owned by username. The group ID is the first one from the username groups list. This operation is performed just after opening the capture device or just after opening the first input PCAP file.
This option does not support multi root-only readable input files as the root privileges are dropped after opening the first file (e.g. -r root-only-access.pcap -R root-only.pcap -l root-only*.pcap).
This option has the same behaviour as the tcpdump(1) option having the same name --relinquish-privileges
-rβ Read from file. Read packets from file, which was created using the-woption oftcpdump(1). This option may be repeated any number of times. Standard input is used if file is"-".
Note that for this option to be useful, tcpdump's-soption should be used to set the snaplen to the MTU of the interface (e.g.,1500) while capturing packets.
-Rβ read from a file, but only to complete TCP flows. This option is used when tcpflow is used to process a series of files that are captured over time. For each time period n, filefile(n).pcapshould be processed with-R file(n).pcap, whilefile(n-1).pcapshould be processed with-r file(n-1).pcap. π-Sname=valueβ sets a name parameter to be equal to value for a plug-in. Use-hhto find out all of the settable parameters. π-sβ strip non-printables. Converts all non-printable characters to the"."character before printing packets to the console or storing them to a file. β¨-T[format]β specifies an arbitrary template for filenames. Here's the whole expansion menu, bestie:
%A expands to source IP address.
%a expands to source IP port.
%B expands to destination IP address.
%b expands to destination IP port.
%T expands to timestamp in ISO8601 format.
%t expands to timestamp in Unix time_t format.
%V expands to "--" if a VLAN is present.
%v expands to the VLAN number if a VLAN is present.
%C expands to "c" if the connection count>0.
%c expands to the connection count if the connection count>0.
%# always expands to the connection count.
%N (connection_number ) % 1000
%K (connection_number / 1000) % 1000
%M (connection_number / 1000000) % 1000
%G (connection_number / 1000000000) % 1000
%% prints a "%".
When the option -T is used, tcpflow ignores options -Fk, -Fm and -Fg. However, the option -T handles '/' within the filename template patern to create sub-directories. For example the following line will create a directory tree out/IP-src/port-src/IP-dst/port-dst.
tcpflow -r packets.pcap -o out -T %A/%a/%B/%b/%c%N.flow
-V,--versionβ print the version number and exit. π-v,--verboseβ verbose operation. Verbosely describe tcpflow's operation. Equivalent to-d 10. π¦-w filename.pcapβ write packets that were not processed tofilename.pcap. Typically this will be UDP packets. π-X filename.xmlβ write a DFXML report tofilename.xml. The file contains a record of every tcp connection, how the tcpflow program was compiled, and the computer on which tcpflow was run. By default tcpflow writes the DFXML report in filereport.xml. πΈ-Zβ don't decompress gzip-compressed streams. π-Kβ retain per flow isolated pcap structure. π«Άexpressionβ selects which packets will be captured. If no expression is given, all packets on the net will be captured. Otherwise, only packets for which expression istruewill be captured.
For the expression syntax, see pcap-filter(7).
The expression argument can be passed to tcpflow as either a single Shell argument, or as multiple Shell arguments, whichever is more convenient. Generally, if the expression contains Shell metacharacters, such as backslashes used to escape protocol names, it is easier to pass it as a single, quoted argument rather than to escape the Shell metacharacters. Multiple arguments are concatenated with spaces before being parsed.
π DFXML report π
The DFXML report is the XML file written by tcpflow to provide tcpflow build details, command line arguments and information about processed flows.
By default the DFXML file is named report.xml. But this filename can be changed using command line option -X.
DFXML file respects the DFXML schema defined by project https://github.com/dfxml-working-group/dfxml_schema. Moreover tcpflow adds two extra XML tags, as illustrated by the following example:
<tcpflow startime='2017-07-22T00:12:21.962782Z' endtime='2017-07-22T00:12:22.097591Z'
family='2' mac_daddr='40:3d:78:57:ed:d4' mac_saddr='00:c5:42:d2:cb:f2'
src_ipn='141.134.34.12' dst_ipn='192.168.0.40' srcport='80' dstport='38797'
packets='4' len='677' caplen='611' />
<tcpflow:result scanner="python" path="python/plugins" module="samplePlugin"
function="sampleFunction">bla bla bla</tcpflow:result>
The first XML tag <tcpflow> provide information about the captured flow. This tag should be renamed <tcpflow:cap> in a future version in order to conform better to DFXML schema.
The second XML tag <tcpflow:result> collects processing results. For the moment, only the scanner python uses this feature.
The XML attributes of <tcpflow> are:
- startime β Reception time of first packet
- endtime β Reception time of last packet
- family
- mac_daddr β Destination MAC address of first packet (printed if any)
- mac_saddr β Source MAC address of first packet (printed if any)
- src_ipn β IP source
- dst_ipn β IP destination
- srcport β TCP port source
- dstport β TCP port destination
- packets β Nummber of packets
- out_of_order_count β Number of times tcpflow has replaced missing payload by zeros in the flow file, for example when capture does not contain the TCP session begin (printed if any)
- violations β Number of protocol violations (printed if any)
- len β Sum of un-truncated length of all packet data (including headers, see
https://stackoverflow.com/q/1491660) - caplen β Sum of captured bytes of all packet data (including headers, printed if different from len)
The XML attributes of <tcpflow:result> are:
- scanner β Name of the scanner
- path β Directory of the scanner module (printed if relevant)
- module β Module name (printed if relevant, used to indicate the python script)
- function β Function name (printed if relevant, used to indicate the function within the python module)
β¨ EXAMPLES β¨
To record all packets arriving at or departing from sundown and extract all of the HTTP attachments:
tcpflow -e http -o outdir host sundown
To record traffic between helios and either hot or ace and bin the results into 1000 files per directory and calculate the MD5 of each flow:
tcpflow -X report.xml -e md5 -o outdir -Fk host helios and \( hot or ace \)
π BUGS π
Please send bug reports to simsong@acm.org.
tcpflow currently does not understand IP fragments. Flows containing IP fragments will not be recorded correctly.
π AUTHORS π
Originally by Jeremy Elson <jelson@circlemud.org>. Substantially modified and maintained by Simson L. Garfinkel <simsong@acm.org>. Network visualization code by Michael Shick <mike@shick.in>
The current version of this software is available at http://digitalcorpora.org/downloads/tcpflow/
An announcement mailing list for this program is at: http://groups.google.com/group/tcpflow-users
π SEE ALSO π
tcpdump(1), nit(4P), bpf(4), pcap(3), pcap-savefile(5), pcap-filter(7)
This page is tcpflow 1.6.2, dated 2013-04-13, and it's serving tcpflow(1) realness. Bye bestie! π π
π¦ where this page comes from
- epel 9: tcpflow 1.6.2-0.1.8d47b53.el9 Β· GPL-1.0-or-later
- fedora 43: tcpflow 1.6.2-0.1.8d47b53.fc43 Β· GPL-1.0-or-later
- fedora 44: tcpflow 1.6.2-0.1.8d47b53.fc44 Β· GPL-1.0-or-later
- nixos 26.05: tcpflow 1.6.1-unstable-2026-01-29
- nixpkgs unstable: tcpflow 1.6.1-unstable-2026-01-29
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms