Python使用scapy生产动态路由图
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python使用scapy生产动态路由图相关的知识,希望对你有一定的参考价值。
scapy模块安装
yum install tcpdump graphviz ImageMagick
打开 https://pypi.org/project/scapy/2.3.3/#files
下载scapy-2.3.3.tar.gz
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
[[email protected] 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生产动态路由图的主要内容,如果未能解决你的问题,请参考以下文章