当前位置: 移动技术网 > IT编程>脚本编程>Python > Python实现TCP探测目标服务路由轨迹的原理与方法详解

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

2019年09月09日  | 移动技术网IT编程  | 我要评论

大学物理学习方法,爱上暴君小甜心,孕妇能喝毛尖茶吗

本文实例讲述了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"

三 结果

四 参考

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网