Lesson 63: Bandwidth Usage Tracker

Track how much bandwidth your system uses over time.

import psutil
import time

old_sent = psutil.net_io_counters().bytes_sent
old_recv = psutil.net_io_counters().bytes_recv

while True:
  net = psutil.net_io_counters()
  sent = net.bytes_sent - old_sent
  recv = net.bytes_recv - old_recv
  print(f"Sent: {sent} bytes, Received: {recv} bytes")
  old_sent = net.bytes_sent
  old_recv = net.bytes_recv
  time.sleep(5)

Monitor usage to detect abnormal spikes or potential attacks.

Next Lesson →