forked from lilendian0x00/xray-knife
/
icmp.go
52 lines (45 loc) · 1.15 KB
/
icmp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package net
import (
"fmt"
"github.com/reenigneserever/xray-knife/network"
"github.com/reenigneserever/xray-knife/utils/customlog"
"github.com/reenigneserever/xray-knife/xray"
"github.com/spf13/cobra"
"net"
"os"
)
var (
destIP net.IP
testCount uint16
)
// IcmpCmd represents the icmp command
var IcmpCmd = &cobra.Command{
Use: "icmp",
Short: "PING or ICMP test config's host",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
parsed, err := xray.ParseXrayConfig(configLink)
if err != nil {
fmt.Fprintf(os.Stderr, "%v", err)
os.Exit(1)
}
generalDetails := parsed.ConvertToGeneralConfig()
if err != nil {
fmt.Fprintf(os.Stderr, "%v", err)
os.Exit(1)
}
icmp, err := network.NewIcmpPacket(generalDetails.Address, testCount)
if err != nil {
customlog.Printf(customlog.Failure, "%v\n", err)
}
err = icmp.MeasureReplyDelay()
if err != nil {
customlog.Printf(customlog.Failure, "MeasureReplyDelay Error: %v", err)
os.Exit(1)
}
},
}
func init() {
IcmpCmd.Flags().StringVarP(&configLink, "config", "c", "", "The xray config link")
IcmpCmd.Flags().Uint16VarP(&testCount, "count", "t", 4, "Count of tests")
}