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

yipeiwu_com7年前Python基础

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

三 结果

四 参考

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

更多关于Python相关内容可查看本站专题:《Python Socket编程技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总

希望本文所述对大家Python程序设计有所帮助。

相关文章

Python操作配置文件ini的三种方法讲解

python 操作配置文件ini的三种方法 方法一:crudini 命令 说明 crudini命令是Linux下的一个操作配置文件的命令工具 用法 crudini --set [--...

Python使用pip安装报错:is not a supported wheel on this platform的解决方法

Python使用pip安装报错:is not a supported wheel on this platform的解决方法

本文讲述了Python使用pip安装报错:is not a supported wheel on this platform的解决方法。分享给大家供大家参考,具体如下: 可能的原因1:安...

python调用java的jar包方法

如下所示: from jpype import * jvmPath = getDefaultJVMPath() jars = ["./Firstmaven-1.0-SNAPSHO...

Python实现的逻辑回归算法示例【附测试csv文件下载】

Python实现的逻辑回归算法示例【附测试csv文件下载】

本文实例讲述了Python实现的逻辑回归算法。分享给大家供大家参考,具体如下: 使用python实现逻辑回归 Using Python to Implement Logistic Reg...

python中时间转换datetime和pd.to_datetime详析

python中时间转换datetime和pd.to_datetime详析

前言 我们在python对数据进行操作时,经常会选取某一时间段的数据进行分析。这里为大家介绍两个我经常用到的用来选取某一时间段数据的函数:datetime( )和pd.to_dateti...