Python使用scapy生產動態路由圖

來源:互聯網
上載者:User

標籤:scapy

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,subprocessimport warnings,loggingwarnings.filterwarnings("ignore", category=DeprecationWarning)#logging.getLogger("scapy.runtime").setLevel(logging.ERROR)from scapy.all import traceroutedomains = 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生產動態路由圖

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.