Python实现TCP探测目标服务路由轨迹

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chengqiuming/article/details/87869348

一 点睛

在此次实践中,通过scapy的traceroute()方法实现探测机到目标服务器的路由轨迹,整个过程的原理见下图,首先通过探测机以SYN方式进行TCP服务扫描,同时启动tcpdump进行抓包,捕获扫描过程经过的所有路由点,再通过graph()方法进行路由IP轨迹绘制,中间调用ASN映射查询IP地理信息并生成svg流程文档,最后使用ImageMagick工 具将svg格式转换成png,流程结束。

二 代码

# -*- coding: utf-8 -*-
import os,sys,time,subprocess
import warnings,logging
#屏蔽scapy 无用告警信息
warnings.filterwarnings("ignore", category=DeprecationWarning)
#屏蔽模块IPv6 多余告警
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import traceroute
#接受输入的域名或IP
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", ASres=None, type="svg")   #生成svg矢量图形
    time.sleep(1)
    #svg转png格式
    subprocess.Popen("/usr/bin/convert test.svg test.png", shell=True)
else:
    print "IP/domain number of errors,exit"

三 结果

四参考

https://github.com/secdev/scapy/issues/1480

猜你喜欢

转载自blog.csdn.net/chengqiuming/article/details/87869348