python-生成动态路由轨迹图(scapy模块)

scapy是一个强大的交互式数据包处理程序,可以用在网络扫描、包嗅探、路由跟踪、单元测试和服务探测

在linux系统上安装

yum -y install tcpdump graphviz ImageMagick  (scapy 需要用到 tcpdump graphviz ImageMagick)

pip3 install scapy -i https://pypi.tuna.tsinghua.edu.cn/simple

创建simple.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os,sys,time,subprocess
import warnings,logging
warnings.filterwarnings('ignore', category=DeprecationWarning) #屏蔽scapy无语的告警信息
logging.getLogger('scapy.runtime').setLevel(logging.ERROR)#屏蔽模块IPv6多余的告警
from scapy.all import traceroute

domains = input('Please input one or more IP/domain:') #接收输入的域名或ip地址
target = domains.split(' ')
dport = [80,7080] #扫描的端口列表

if len(target) >=1 and target[0]!= '':
    print('长度:%s' % len(target))
    res,unans = traceroute(target,dport=dport,retry=-2) #启动路由跟踪
    res.graph(target='> test.svg') #生成svg矢量图形
    time.sleep(1)
    subprocess.Popen('/usr/bin/convert test.svg test.png', shell=True)#svg转png格式
else:
    print('IP/domain number of errots,exit!')
原文地址:https://www.cnblogs.com/fuyuteng/p/12587599.html