一,工具简介
tcpsubnet工具
根据目标子网统计吞吐量。
这个工具只在IPv4环境下工作,并允许用户指定特定的子网进行监控。通过使用tcpsubnet
,用户可以实时地观察特定子网内TCP流量的变化和分布情况,从而帮助进行网络性能调优、故障排查和安全监控等工作。
二,代码示例
#!/usr/bin/env python
import argparse
import json
import logging
import struct
import socket
from bcc import BPF
from datetime import datetime as dt
from time import sleep
# 参数
examples = """examples:
./tcpsubnet # Trace TCP sent to the default subnets:
# 127.0.0.1/32,10.0.0.0/8,172.16.0.0/12,
# 192.168.0.0/16,0.0.0.0/0
./tcpsubnet -f K # Trace TCP sent to the default subnets
# aggregated in KBytes.
./tcpsubnet 10.80.0.0/24 # Trace TCP sent to 10.80.0.0/24 only
./tcpsubnet -J # Format the output in JSON.
"""
default_subnets = "127.0.0.1/32,10.0.0.0/8,&