🐾 Get the nftables counters easier to read

Overview

nft-stats

Get the nftables counters easier to read

It kind of hard to read the output of nft list ruleset so there is a small program parcising the output to make counter et stats easier to read.

I make the ouput look like iptables -nvL

Usage

nft-stats

TODO

  • Color
  • Counter when nft named counters into the config

Install

With APT (recommended)

echo "deb [signed-by=/usr/share/keyrings/azlux-archive-keyring.gpg] http://packages.azlux.fr/debian/ bullseye main" | sudo tee /etc/apt/sources.list.d/azlux.list
sudo wget -O /usr/share/keyrings/azlux-archive-keyring.gpg  https://azlux.fr/repo.gpg
sudo apt update
sudo apt install nft-stats

Manually

You can just clone the project, it's a one-script (nft-stats.py) project. But you will have not auto-update.

Example

Without nft-stats

command : nft list ruleset

Click to expand!
root@AZLUX-PC:~# nft list ruleset
table ip filter {
        set router {
                type ipv4_addr
                comment "Azlux routers"
                elements = { xxxx/32,xxxx/28,xxxx/32 }
        }
        set ip_source_users {
                type ipv4_addr
                flags interval
                elements = { xxxx,xxxx,xxxx,xxxx }
        }
        chain OUTPUT {
                type filter hook output priority filter; policy accept;
                oif "eth0" ip daddr @router tcp dport 179 counter packets 8345 bytes 410788 accept
                oif "eth0" tcp dport 179 counter packets 0 bytes 0 drop
        }

        chain INPUT {
                type filter hook input priority filter; policy accept;
                ct state established accept
                iif "lo" accept
                iif "eth0" ip saddr @ip_source_users tcp dport { 22, 80, 443 } counter packets 2361 bytes 141660 accept
                counter packets 8742 bytes 454622 drop
        }
}
table ip6 filter {
        set ip6_source_users {
                type ipv6_addr
                flags interval
                elements = { xx:xx:xx:xx::xx,
                             xx:xx:xx:xx::xx }
        }

        chain INPUT {
                type filter hook input priority filter; policy accept;
                ct state established accept
                iif "lo" accept
                icmpv6 type { destination-unreachable, packet-too-big, time-exceeded, parameter-problem, mld-listener-query, mld-listener-report, mld-listener-done, nd-router-solicit, nd-router-advert, nd-neighbor-solicit, nd-neighbor-advert, ind-neighbor-solicit, ind-neighbor-advert, mld2-listener-report } accept comment "Accept ICMPv6"
                iif "eth0" ip6 saddr @ip6_source_users tcp dport { 22, 80, 443 } counter packets 0 bytes 0 accept
                counter packets 4 bytes 321 drop
        }
}
table inet filter {
        chain FORWARD {
                type filter hook forward priority filter; policy drop;
                counter packets 0 bytes 0 drop
        }
}

With nft-stats

command : nft-stats

Click to expand!
root@AZLUX-PC:~# nft-stats

OUTPUT IP (policy ACCEPT)
pkts       bytes      action
8240       396.13K    ACCEPT  oif "eth0" ip daddr @router tcp dport 179
0          0          DROP    oif "eth0" tcp dport 179

INPUT IP (policy ACCEPT)
pkts       bytes      action
-          -          ACCEPT  oif "eth0" tcp dport 179
-          -          ACCEPT  oif "eth0" tcp dport 179
2310       135.35K    ACCEPT  iif "eth0" ip saddr @ip_source_users tcp dport  22, 80, 443
8659       439.32K    DROP    

INPUT IP6 (policy ACCEPT)
pkts       bytes      action
-          -          ACCEPT  ct state established accept
-          -          ACCEPT  iif "lo" accept
-          -          ACCEPT  icmpv6 type  destination-unreachable, packet-too-big, time-exceeded, parameter-problem, mld-listener-query, mld-listener-report, mld-listener-done, nd-router-solicit, nd-router-advert, nd-neighbor-solicit, nd-neighbor-advert, ind-neighbor-solicit, ind-neighbor-advert, mld2-listener-report  accept comment "Accept ICMPv6"
0          0          ACCEPT  iif "eth0" ip6 saddr @ip6_source_users tcp dport  22, 80, 443
4          321        DROP    

FORWARD INET (policy DROP)
pkts       bytes      action
0          0          DROP    
You might also like...
🐍 Python CLI tool to get public information from a GitHub account
🐍 Python CLI tool to get public information from a GitHub account

🐍 Gitter 🐍 Python CLI tool to get public information from a GitHub account 🤔 What's this? Gitter is a open-source project created to easily uses th

Python-Stock-Info-CLI: Get stock info through CLI by passing stock ticker.
Python-Stock-Info-CLI: Get stock info through CLI by passing stock ticker.

Python-Stock-Info-CLI Get stock info through CLI by passing stock ticker. Installation Use the following command to install the required modules at on

Gitfetch is a simple tool to get github user details
Gitfetch is a simple tool to get github user details

Gitfetch Just a (cli?) tool to get github user details 🙂 Installation 📂 Install Gitfetch via pypi pip install gitfetch or pip install git+https://g

A command line interface to interact with the Hypixel api allowing the user to get stats, leaderboards, etc

HyConsole is a way to get data on players and leaderboards from the Hypixel Minecraft server from the command line. Keep in mind I have no a

ForX - get forex quotes from the terminal

A command line tool for checking exchange rates between currencies, both crypto and fiat.

Wik is use to get information about anything on the shell using Wikipedia.
Wik is use to get information about anything on the shell using Wikipedia.

WIK wik is a tool to view wikipedia pages from your terminal. It also let you search for any wikipedia up to date article on one query from your termi

Read write method - Read files in various types of formats

一个关于所有格式文件读取的方法 1。 问题描述: 各种各样的文件格式,读写操作非常的麻烦,能够有一种方法,可以整合所有格式的文件,方便用户进行读取和写入。 2

To lazy to read your homework ? Get it done with LOL

LOL To lazy to read your homework ? Get it done with LOL Needs python 3.x L:::::::::L OO:::::::::OO L:::::::::L L:::::::

Get Notified about vaccine availability in your location on email & sms ✉️! Vaccinator Octocat tracks & sends personalised vaccine info everday. Go get your shot ! 💉
Get Notified about vaccine availability in your location on email & sms ✉️! Vaccinator Octocat tracks & sends personalised vaccine info everday. Go get your shot ! 💉

Vaccinater Get Notified about vaccine availability in your location on email & sms ✉️ ! Vaccinator Octocat tracks & sends personalised vaccine info ev

Want to get your driver's license? Can't get a appointment because of COVID? Well I got a solution for you.

NJDMV-appoitment-alert Want to get your driver's license? Can't get a appointment because of COVID? Well I got a solution for you. We'll get you one i

Get-web-images - A python code that get images from any site

image retrieval This is a python code to retrieve an image from the internet, a

Get-Phone-Number-Details-using-Python - To get the details of any number, we can use an amazing Python module known as phonenumbers.

Get-Phone-Number-Details-using-Python To get the details of any number, we can use an amazing Python module known as phonenumbers. We can use the amaz

Dead simple CLI tool to try Python packages - It's never been easier! :package:
Dead simple CLI tool to try Python packages - It's never been easier! :package:

try - It's never been easier to try Python packages try is an easy-to-use cli tool to try out Python packages. Features Install specific package versi

A series of convenience functions to make basic image processing operations such as translation, rotation, resizing, skeletonization, and displaying Matplotlib images easier with OpenCV and Python.
A series of convenience functions to make basic image processing operations such as translation, rotation, resizing, skeletonization, and displaying Matplotlib images easier with OpenCV and Python.

imutils A series of convenience functions to make basic image processing functions such as translation, rotation, resizing, skeletonization, and displ

:electric_plug: Generating short urls with python has never been easier
:electric_plug: Generating short urls with python has never been easier

pyshorteners A simple URL shortening API wrapper Python library. Installing pip install pyshorteners Documentation https://pyshorteners.readthedocs.i

:electric_plug: Generating short urls with python has never been easier
:electric_plug: Generating short urls with python has never been easier

pyshorteners A simple URL shortening API wrapper Python library. Installing pip install pyshorteners Documentation https://pyshorteners.readthedocs.i

db.py is an easier way to interact with your databases
db.py is an easier way to interact with your databases

db.py What is it Databases Supported Features Quickstart - Installation - Demo How To Contributing TODO What is it? db.py is an easier way to interact

Comments
  • Add Support for Python 3.6

    Add Support for Python 3.6

    If you currently try to run it on Python 3.6, it will fail with the following message:

    Traceback (most recent call last):
      File "./nft-stats.py", line 111, in <module>
        main()
      File "./nft-stats.py", line 104, in main
        out = run_command(args)
      File "./nft-stats.py", line 42, in run_command
        nft_run = subprocess.run(command, shell=True, capture_output=True)
      File "/usr/lib64/python3.6/subprocess.py", line 423, in run
        with Popen(*popenargs, **kwargs) as process:
    TypeError: __init__() got an unexpected keyword argument 'capture_output'
    

    The culprit is this line:

        nft_run = subprocess.run(command, shell=True, capture_output=True)
    

    This is due to Python 3.6 not supporting the option capture_output. The solution is changing it to this instead:

        nft_run = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    

    This works on Python 3.6 and above from my testing (and should work on 3.5 as well)

    opened by ossie-git 1
Releases(0.3)
Owner
Sometime on Libera #mumble.
null
Several tools that can be added to your `PATH` to make your life easier.

CK-CLI Tools Several tools that can be added to your PATH to make your life easier. prettypath Prints the $PATH variable in a human-readable way. It a

Christopher Kumm 2 Apr 21, 2022
A project designed to make taking notes easier than ever - by doing it all on command line

A project designed to make taking notes easier than ever - by doing it all on command line! Yes, all of your files are easily accessible through one command interface, and can be written to at any time! #ad #sponsored

null 1 Dec 10, 2021
A simple script to make the operation of AltServer-Linux more easier with cli

A simple script to make the operation of AltServer-Linux more easier with cli

powen 23 Dec 13, 2022
Get Air Quality Index for your city/country 😷

Air Quality Index CLI Get Air Quality index for your City. Installation $ pip install air-quality-cli Contents Air Quality Index CLI Installation Cont

Yankee 40 Oct 21, 2022
Get latest astronomy job and rumor news in your command line

astrojobs Tired of checking the AAS job register and astro rumor mill for job news? Get the latest updates in the command line! astrojobs automaticall

Philip Mocz 19 Jul 20, 2022
Fetch is use to get information about anything on the shell using Wikipedia.

Fetch Search wikipedia article on command line [Why This?] [Support the Project] [Installation] [Configuration] Why this? Fetch helps you to quickly l

Yash Singh 340 Dec 18, 2022
Get COVID-19 vaccination schedules from booking.moh.gov.ge in the CLI

vaccination.py Get COVID-19 vaccination schedules from booking.moh.gov.ge in the CLI. Installation $ pip install vaccination Usage Make sure the Pytho

Temuri Takalandze 11 Dec 8, 2021
👻 Ghoul is an easy to use information service, allowing you to get/add information on someone or something directly from your terminal.

?? Ghoul is an easy to use information service, allowing you to get/add information on someone or something directly from your terminal. It c

Billy 11 Nov 10, 2021
A CLI tools to get you started on any project in any language

Any Template A faster easier to Quick start any programming project. Installation pip3 install any-template Features No third party dependencies. Tem

Adwaith Rajesh 2 Jan 11, 2022
Command-line interface to PyPI Stats API to get download stats for Python packages

pypistats Python 3.6+ interface to PyPI Stats API to get aggregate download statistics on Python packages on the Python Package Index without having t

Hugo van Kemenade 140 Jan 3, 2023