Python使用scapy生產動態路由圖
yum install tcpdump graphviz ImageMagick
打開 https://pypi.org/project/scapy/2.3.3/#files
下載scapy-2.3.3.tar.gz
wget https://files.pythonhosted.org/packages/ac/14/c792a14b9f8bc4bb9c74c0594c167a2da36e31964098d9e27202142cbd7d/scapy-2.3.3.tgz
tar zxf scapy-2.3.3.tar.gz
cd scapy-2.3.3
python setup.py install
探測百度的路由圖
#!/usr/bin/env python # -*- coding: utf-8 -*- import os,sys,time,subprocess import warnings,logging warnings.filterwarnings("ignore", category=DeprecationWarning) #logging.getLogger("scapy.runtime").setLevel(logging.ERROR) from scapy.all import traceroute domains = raw_input('Please input one or more IP/domain: ') target = domains.split(' ') dport = [80] if len(target) >= 1 and target[0]!='': res,unans = traceroute(target,dport=dport,retry=-2) res.graph(target="> test.svg") time.sleep(1) subprocess.Popen("/usr/bin/convert test.svg test.png", shell=True) else: print "IP/domain number of errors,exit"
執行 Python png.py
生成test.png
[root@zabbix-agent home]# python simple.py
Please input one or more IP/domain: www.baidu.com
Begin emission:
*Finished to send 30 packets.
************************Begin emission:
Finished to send 5 packets.
Begin emission:
Finished to send 5 packets.
Received 25 packets, got 25 answers, remaining 5 packets
14.215.177.38:tcp80
1 192.168.1.1 11
2 100.64.0.1 11
3 59.38.106.57 11
5 113.96.4.14 11
10 14.215.177.38 SA
11 14.215.177.38 SA
12 14.215.177.38 SA
13 14.215.177.38 SA
14 14.215.177.38 SA
15 14.215.177.38 SA
16 14.215.177.38 SA
17 14.215.177.38 SA
18 14.215.177.38 SA
19 14.215.177.38 SA
20 14.215.177.38 SA
21 14.215.177.38 SA
22 14.215.177.38 SA
23 14.215.177.38 SA
24 14.215.177.38 SA
25 14.215.177.38 SA
26 14.215.177.38 SA
27 14.215.177.38 SA
28 14.215.177.38 SA
29 14.215.177.38 SA
30 14.215.177.38 SA
註意scapy版本 高版本2.4會報錯
用2.3.3版本正好
Python使用scapy生產動態路由圖