zoukankan      html  css  js  c++  java
  • Python—路由追踪(并生成追踪图片)

    需要先安装两个包

    [root@localhost ~]# yum install graphviz            // 为了使用dot命令
    [root@localhost ~]# yum install ImageMagick         // 为了使用/usr/bin/convert命令

    python脚本代码如下

    #!/usr/bin/evn python
    #-*-coding:utf-8 -*-
    
    import os,sys,time,subprocess
    import warnings,logging
    from scapy.all import traceroute
    from scapy.as_resolvers import AS_resolver_radb
    
    warnings.filterwarnings("ignore", category=DeprecationWarning)
    logging.getLogger("scapy.runtine").setLevel(logging.ERROR)
    
    domains = raw_input('please input the domain or IP what you want: ')
    target = domains.split(" ")
    dport = [80, 21]
    
    if len(target) >= 1 and target[0] != '':
        # 启动路由跟踪
        res, unans = traceroute(target, dport=dport, retry=-2)
        # traceroute 生成的信息绘制成svg
        # res.graph(target="> graph.svg")
        res.graph(target="> graph.svg", ASres=AS_resolver_radb(), type="svg")
        time.sleep(2)
        # svg 转格式为 png
        subprocess.Popen("/usr/bin/convert graph.svg graph.png", shell=True)
    else:
        print("IP/domain number of errors, exit")

    注意:traceroute程序都需要root来运行。traceroute函数可以传入以列表格式的多个域名/IP,和多个端口(这里有80和21)。

  • 相关阅读:
    两年来的读书小总结(20112013)
    给无边框窗体添加任务栏右键菜单
    使用 yum 命令安装本地安装QQ
    删除非空目录
    gcc安装
    WIN32::OLE操作之excel
    [题解] 组合数学13题
    [算法] 高斯消元及其应用
    [算法] Lucas 定理
    [算法] 最小费用最大流
  • 原文地址:https://www.cnblogs.com/liuhaidon/p/11704017.html
Copyright © 2011-2022 走看看