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!')

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM