Python实现TCP探测目标服务路由轨迹的原理与方法详解

2022-10-16,,,,

本文实例讲述了python实现tcp探测目标服务路由轨迹原理与方法。分享给大家供大家参考,具体如下:

一 点睛

在此次实践中,通过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"

三 结果

四 参考

《Python实现TCP探测目标服务路由轨迹的原理与方法详解.doc》

下载本文的Word格式文档,以方便收藏与打印。