github.com/GuanceCloud/cliutils@v1.1.21/dialtesting/traceroute_test.go (about)

     1  // Unless explicitly stated otherwise all files in this repository are licensed
     2  // under the MIT License.
     3  // This product includes software developed at Guance Cloud (https://www.guance.com/).
     4  // Copyright 2021-present Guance, Inc.
     5  
     6  package dialtesting
     7  
     8  import (
     9  	"fmt"
    10  	"testing"
    11  )
    12  
    13  func TestTraceroute(t *testing.T) {
    14  	routes, err := TracerouteIP("180.101.49.13", &TracerouteOption{
    15  		Hops:  30,
    16  		Retry: 3,
    17  	})
    18  
    19  	fmt.Println(routes, err)
    20  
    21  	for index, route := range routes {
    22  		fmt.Printf("%d ", index)
    23  		for _, item := range route.Items {
    24  			fmt.Printf("%s %f ", item.IP, item.ResponseTime)
    25  		}
    26  		fmt.Printf(" total: %d, failed: %d, loss: %f, avg: %f, max: %f, min: %f, std: %f\n", route.Total, route.Failed, route.Loss, route.AvgCost, route.MaxCost, route.MinCost, route.StdCost)
    27  	}
    28  }