zoukankan      html  css  js  c++  java
  • python脚本之traceroute生成路由跟踪图片

    脚本 route.py

    #!/usr/bin/python

    #conding=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

    domain = raw_input('Please input on or more IP/domains:')     #输入域名
    target = domain.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 route.py

    运行提示:
    Please input on or more IP/domains:www.hao123.com
    .Begin emission:
    ******Finished to send 30 packets.
    ********************Begin emission:
    Finished to send 4 packets.
    Begin emission:
    Finished to send 4 packets.

    Received 27 packets, got 26 answers, remaining 4 packets
    115.239.217.167:tcp80
    1 192.168.1.1 11
    2 121.15.7.25 11
    3 113.106.39.225 11
    5 183.56.65.42 11
    7 202.97.84.77 11
    9 115.239.209.10 11
    10 115.239.209.22 11
    12 115.239.217.167 SA
    13 115.239.217.167 SA
    14 115.239.217.167 SA
    15 115.239.217.167 SA
    16 115.239.217.167 SA
    17 115.239.217.167 SA
    18 115.239.217.167 SA
    19 115.239.217.167 SA
    20 115.239.217.167 SA
    21 115.239.217.167 SA
    22 115.239.217.167 SA
    23 115.239.217.167 SA
    24 115.239.217.167 SA
    25 115.239.217.167 SA
    26 115.239.217.167 SA
    27 115.239.217.167 SA
    28 115.239.217.167 SA
    29 115.239.217.167 SA
    30 115.239.217.167 SA

    生成的图片效果:

  • 相关阅读:
    vue的环境的搭建
    rem
    web前端面试题总结
    vue遇到的一些问题
    栅格布局的理解
    利用node的http模块创建一个简单的http服务器
    node 常用的一些终端的命令的快捷键
    node 环境变量设置方法
    CentOS7.5搭建Hadoop2.7.6完全分布式集群
    UUID做主键,好还是不好?这是个问题
  • 原文地址:https://www.cnblogs.com/to-be-rich/p/7262182.html
Copyright © 2011-2022 走看看