

This function accepts several parameters, one of the important ones is the callback that is called whenever a packet is captured. If you're not familiar with Scapy, then to be able to sniff packets, we have to use the sniff() function provided by this library.



Now let's enter the loop that gets the same stats but after a delay so we can calculate the download and upload speed: while True: # extract the total bytes sent and receivedīytes_sent, bytes_recv = io.bytes_sent, io.bytes_recv Next, we will use _io_counters() function that returns the network input and output statistics: # get the network I/O stats from psutil Starting with the simplest program Let's import psutil and make a function that prints the bytes in a nice format: import psutilįor unit in : Psutil is a cross-platform library for retrieving information on running processes and system and hardware information in Python, we will be using it for retrieving network statistics as well as established connections. To get started, let's install the required libraries: $ pip install psutil scapy pandas Have you ever wanted to make a program that monitors the network usage of your machine? In this tutorial, we will make three Python scripts that monitor total network usage, network usage per network interface, and network usage per system process:
