# How to use nDPI from CLI to analyse network traffic | ntop

[Blog](https://www.ntop.org/blog/)[nDPI](https://www.ntop.org/category/ndpi/)

# How to use nDPI from CLI to analyse network traffic

November 23, 20191 min read

Most people use nDPI indirectly being it part of ntopng and many other non-ntop developed tools. However not many people know that nDPI can also be used from the command line to analyse network traffic. This is useful to create scripts to automate detection of specific issues. ndpiReader is a testing tool used to demonstrate the library features as well run validation tests. With this tool is also possible to generate a report in CSV format that can be analysed with tools such as [q](http://harelba.github.io/q/).

Below you can find some practical examples of how this technique can be used in real life. Suppose we need to analyse some malware traffic in order to spot anomalies. A good starting point for sample pcap files is the [CIC dataset](https://www.unb.ca/cic/datasets/ids-2018.html) or this [website](https://www.malware-traffic-analysis.net) or you can use any pcap you already have collected as those part of the nDPI [test set](https://github.com/ntop/nDPI/tree/dev/tests/pcap).

From the CIC dataset, support you want to analyse what flows are affected by [Slow DoS](https://en.wikipedia.org/wiki/Slowloris_(computer_security)).

$ ndpiReader -i dos\_slow.pcap -C dos\_slow.csv

Dumps flow analysis results into CSV file that contains the following fields

$ head -1 ~/Downloads/Ricci/dos\_slow.csv
#flow\_id,protocol,first\_seen,last\_seen,duration,src\_ip,src\_port,dst\_ip,dst\_port,ndpi\_proto\_num,ndpi\_proto,src2dst\_packets,src2dst\_bytes,src2dst\_goodput\_bytes,dst2src\_packets,dst2src\_bytes,dst2src\_goodput\_bytes,data\_ratio,str\_data\_ratio,src2dst\_goodput\_ratio,dst2src\_goodput\_ratio,iat\_flow\_min,iat\_flow\_avg,iat\_flow\_max,iat\_flow\_stddev,iat\_c\_to\_s\_min,iat\_c\_to\_s\_avg,iat\_c\_to\_s\_max,iat\_c\_to\_s\_stddev,iat\_s\_to\_c\_min,iat\_s\_to\_c\_avg,iat\_s\_to\_c\_max,iat\_s\_to\_c\_stddev,pktlen\_c\_to\_s\_min,pktlen\_c\_to\_s\_avg,pktlen\_c\_to\_s\_max,pktlen\_c\_to\_s\_stddev,pktlen\_s\_to\_c\_min,pktlen\_s\_to\_c\_avg,pktlen\_s\_to\_c\_max,pktlen\_s\_to\_c\_stddev,client\_info,server\_info,tls\_version,ja3c,tls\_client\_unsafe,ja3s,tls\_server\_unsafe,ssh\_client\_hassh,ssh\_server\_hassh

You can now run this query to find out the top 10 slow DoS flows

q -H -d ',' "select src\_ip,src\_port,dst\_ip,dst\_port,ndpi\_proto,duration from ./dos\_slow.csv where dst2src\_goodput\_ratio<10 order by duration desc limit 10"
172.16.0.1,54240,192.168.10.50,80,HTTP,1241.436
172.16.0.1,53816,192.168.10.50,80,HTTP,1239.08
172.16.0.1,53824,192.168.10.50,80,HTTP,1239.078
172.16.0.1,53834,192.168.10.50,80,HTTP,1239.077
172.16.0.1,53840,192.168.10.50,80,HTTP,1239.077
172.16.0.1,53846,192.168.10.50,80,HTTP,1239.076
172.16.0.1,53852,192.168.10.50,80,HTTP,1239.075
172.16.0.1,53858,192.168.10.50,80,HTTP,1239.074
172.16.0.1,53866,192.168.10.50,80,HTTP,1239.073
172.16.0.1,53872,192.168.10.50,80,HTTP,1239.072

Suppose you want to know the amount of traffic the top IPe in [netfix.pcap](https://github.com/ntop/nDPI) have spent watching NetFlix. First run ndpiReader as follows

$ cd nDPI/tests/pcap
$ ../../example/ndpiReader -i netflix.pcap -C /tmp/netflix.csv

then do

$ q -H -d ',' "select src\_ip,SUM(src2dst\_bytes+dst2src\_bytes) from /tmp/netflix.csv where ndpi\_proto like '%NetFlix%' group by src\_ip"
192.168.1.7,6151821

Possibilites are basically endless.

Enjoy!

## Keep reading

ntopngNov 23, 2026

### [Modeling Your Network: Part I](https://www.ntop.org/network-model-intro/)

ntopng is introducing continuous network learning to help administrators close visibility gaps in dynamic networks, starting with a new Server Model feature. Using DPI and historical flow data, the system passively discovers and baselines core servers—alerting operators to unauthorized services, unresponsive hosts, or traffic anomalies while automatically updating network configurations to reduce false-positive security alerts.

AINov 7, 2026

### [Sharkfest 26EU: HowTo Detect Stealth VPN and AI Inference Traffic](https://www.ntop.org/sharkfest-26eu-howto-detect-stealth-vpn-and-ai-inference-traffic/)

Earlier this week we have presented at Sharkfest Europe 2026 a presentation of our work about traffic detection of Stealth VPNs and AI Inference. The presentation addresses the challenges of detecting modern obfuscated network traffic, specifically from stealth VPNs and custom/local artificial intel

nDPINov 7, 2026

### [Detecting CVE-2026-98432 using nDPI/ntopng](https://www.ntop.org/detecting-cve-2026-98432-using-ndpi-ntopng/)

CVE-2026-98432 is a critical, 9.8-severity use-after-free (UAF) vulnerability in the Linux kernel’s IPv4 TCP networking stack. It allows an unauthenticated remote attacker to potentially cause system crashes, memory corruption, or execute arbitrary commands with root privileges. From a network stand

## Try it on your own network

Download the free Community edition and see your first flows in five minutes.

[Download ntopng free](https://www.ntop.org/support/documentation/software-installation/)[Talk to an engineer](https://www.ntop.org/support/need-help/contacts/)
Source: https://www.ntop.org/how-to-use-ndpi-from-cli-to-analyse-network-traffic/