Giter VIP home page Giter VIP logo

traceroute's Introduction

Traceroute

简介

用 python 写的 Traceroute 程序。输入指定 ip 地址,程序会自动列出中间经过的路由器、往返时延。

用到的模块主要有 socket、struct、select等。

原理

核心:ICMP网际控制报文协议、python socket编程。

思路:当路由器收到一份 ip 数据报,如果该报文的 ttl 字段值为 1 ,则意味着它在网路中的生存周期已经消耗殆尽了,本路由处理后还未到达目的主机的话,需要将该数据报丢弃,并给信源主机发送一份 ICMP 超时报文(包含该中间路由器的地址)。

这意味着:发送一份 ttl 字段为 n 的 ip 数据报给目的主机,就可以得到该路由路径中的第 n 个路由器的 ip 地址。那么我们 ip 数据报的 ttl 字段值从 1 开始依次递增,就可以获得所有中间路由的 ip 地址。 当 ip 数据报到达目的主机时,由于已经到达目的主机,因此不会再发送 ICMP 超时报文了,而是 ICMP 应答报文。 通过区分收到的 ICMP 报文是超时(type = 11)还是目的不可达(type = 3),以判断程序应该何时结束。

测试环境

操作系统:centOS 6

开发平台:python 2.7

在 windows 机器上,可能会因为默认的防火墙设置导致程序不正常运行,最好用 Linux 运行吧。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.