# Scripting ntopng with Lua | ntop

> The ntopng architecture is divided in three layers: Ingress layer (flow or packet capture). Monitoring engine: the ntopng core. Lua scripting engine Data expo

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

# Scripting ntopng with Lua

January 15, 20142 min read

The ntopng architecture is divided in three layers:

-   Ingress layer (flow or packet capture).
-   Monitoring engine: the ntopng core.
-   Lua scripting engine
-   Data export layer (via web, syslog or log files).

[![ntopng](/images/2014/01/ntopng.webp)](https://www.ntop.org/images/2014/01/ntopng.webp)

Thanks to the scripting engine, ntopng is fully scriptable. This means that via Lua you can extract the monitoring information and report it into HTML pages or export it to third party applications. The ntopng Lua API is pretty simple it consists of two classes, [ntop](https://www.ntop.org/support/documentation/users-guides/) and [interface](https://www.ntop.org/support/documentation/users-guides/). ntopng also comes with some [example scripts](https://github.com/ntop/ntopng) that highlight the main API functionalities, although the best demo is perhaps the ntopng web interface. The embedded HTTP(S) web server is responsible for parsing GET/POST parameters (if any) and places them into the \_GET global scripts variable so that they can be accessed from Lua. Scripts are also used in ntopng to execute [periodic actions](https://github.com/ntop/ntopng) such as dumping throughput and top talkers to disk. ntopng is fully reentrant thus means that multiple scripts can be safely executed simultaneously.

An example of Lua scripting is the following.

> \--
> -- (C) 2013 - ntop.org
> --
> dirs = **ntop.getDirs**()
> package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
> 
> require "lua\_utils"
> 
> sendHTTPHeader('text/html')
> 
> **interface.find**(ifname)
> ifstats = **interface.getStat**s()
> 
> type = **\_GET**\["type"\]
> 
> if((type == nil) or (type == "size")) then
> what = ifstats\["pktSizeDistribution"\]
> end
> 
> local pkt\_distribution = {
> \['upTo64'\] = '<= 64',
> \['upTo128'\] = '64 <= 128',
> \['upTo256'\] = '128 <= 256',
> \['upTo512'\] = '256 <= 512',
> \['upTo1024'\] = '512 <= 1024',
> \['upTo1518'\] = '1024 <= 1518',
> \['upTo2500'\] = '1518 <= 2500',
> \['upTo6500'\] = '2500 <= 6500',
> \['upTo9000'\] = '6500 <= 9000', \['above9000'\] = '> 9000'
> }
> 
> tot = 0
> for key, value in pairs(what) do
> tot = tot + value
> end
> 
> threshold = (tot \* 5) / 100
> 
> print "\[\\n"
> num = 0
> sum = 0
> for key, value in pairs(what) do
> if(value > threshold) then
> if(num > 0) then
> print ",\\n"
> end
> 
> print("\\t { \\"label\\": \\"" .. pkt\_distribution\[key\] .."\\", \\"value\\": ".. value .." }")
> num = num + 1
> sum = sum + value
> end
> end
> 
> if(sum < tot) then
> print("\\t, { \\"label\\": \\"Other\\", \\"value\\": ".. (tot-sum) .." }")
> end
> 
> print "\\n\]"

In bold the API calls are highlighted. ntopng transparently handles the redirection of the output into web pages, and mix of HTML with Lua code similar to what happens with other scripting languages such as PHP. Developers familiar with web scripting languages should become familiar with ntopng pretty quickly and thus extend and customise it without much hassle.

Please make sure that you share your scripts with the ntopng community.

## Keep reading

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

[![](/images/2026/09/Screenshot-2026-09-09-151028-1.webp)](https://www.ntop.org/october-20th-join-us-for-the-ntopng-7-0-webinar/)

AnnounceOct 5, 2026

### [October 20th: Join us for the ntopng 7.0 Webinar](https://www.ntop.org/october-20th-join-us-for-the-ntopng-7-0-webinar/)

Is your network monitoring keeping pace with AI, larger infrastructures, and the growing need for real observability? We’re excited to introduce ntopng 7.0, alongside new releases of the rest of the ntop…

[![](/images/2026/09/Screenshot-2026-09-09-163410-1.webp)](https://www.ntop.org/ntopng-user-interface-introducing-the-new-navigation-bar/)

ntopngSep 21, 2026

### [ntopng User Interface: Introducing the New Navigation Bar](https://www.ntop.org/ntopng-user-interface-introducing-the-new-navigation-bar/)

In our continuous effort to improve user experience and make network monitoring more intuitive, we have completely redesigned the ntopng Navigation Bar. As our feature set expands—with crucial additions like the nAnalyst…

## 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/scripting-ntopng-with-lua/