Here is a simple Python script to monitor network traffic.
import psutil
def monitor_network():
# Get the network I/O statistics for all interfaces
net_io_counters = psutil.net_io_counters(pernic=True)
# Loop through each interface
for interface, info in net_io_counters.items():
print(f"Interface: {interface}")
print(f"Bytes sent: {info.bytes_sent}")
print(f"Bytes received: {info.bytes_recv}")
print("\n")
# Continuously monitor network traffic every second
while True:
monitor_network()
time.sleep(1)
This script uses the psutil
library to get the network I/O statistics for all network interfaces. It then loops through each interface and prints the number of bytes sent and received. The script continuously monitors the network traffic every second by using an infinite loop and the time.sleep
function.
Here's a basic example of web scraping in Python using the requests and BeautifulSoup libraries:…
Here's an example of how you can use Python to SSH into a remote server…
Here's an example of a Python class that represents a rectangle: class Rectangle: def __init__(self,…
Here is a simple Python script that interacts with Active Directory (AD) using the pyad…
Here's a Python script to monitor disk usage on a system and send an email…
Running a Python script on a Mac is a relatively straightforward process that can be…