Git Product home page Git Product logo

go-mtr's Introduction

Go-MTR


简介

MTR

程序基于: https://github.com/tonobo/mtr https://github.com/liuxinglanyue/mtr 进行了一定的bug修复和优化开发。支持单机多协程并发mtr探测,同时支持ipv4和ipv6。

PING

支持单机多协程发起ping探测,同时支持ipv4和ipv6

案例

var targets = []string{"216.58.200.78", "52.74.223.119", "123.125.114.144"}

func main() {
    // 发起mtr操作
	for _, val := range targets {
		go func(target string) {
			for {
				mm, err := mtr.Mtr(target, 30, 10, 800)
				if err != nil {
					fmt.Println(err)
				}
				fmt.Println(mm)

				time.Sleep(60 * time.Second)
			}
		}(val)
	}

    // 发起ping操作
	for _, val := range targets {
		go func(target string) {
			for {
				mm, err := ping.Ping(target, 10, 800, 10)
				if err != nil {
					fmt.Println(err)
				}
				fmt.Println(mm)

				time.Sleep(60 * time.Second)
			}
		}(val)
	}

	select {}
}

注:针对mtr可设定的参数包括maxHops(最大跳数)、sntSize(发送数据包数量)、timeoutMs(icmp包超时时间)。针对ping探测可设定的参数包括count(数据包数量)、timeoutMs(超时时间)、intervalMs(发包间隔)

原理

mtr发送icmp数据报,先发送TTL为1的,到第一个路由器TTL减1,并返回一个超时的ICMP报文,这样就得到了第一个路由器的地址; 接下来发送TTL值为2的报文,得到第二个路由器的报文; 直到找到目的IP地址,mtr一次探测结束。然后根据发送数据包的数量,重新发起mtr探测,记录结果。

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.