diff --git a/goping/goping.go b/goping/goping.go index 03e6fcb..02d371c 100644 --- a/goping/goping.go +++ b/goping/goping.go @@ -5,6 +5,8 @@ import ( "encoding/binary" "fmt" "net" + "os" + "os/signal" "time" ) @@ -147,6 +149,12 @@ func Ping(domain string, PS int) { } + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt, os.Kill) + + s := <-c + fmt.Println("Got signal:", s) + fmt.Printf("--- %s ping statistics ---\n", raddr.String()) fmt.Printf("%d packets transmitted, %f lost, %.2f%% packet loss, time 1000ms\n", icmp_seq, dropPack, dropPack/float64(icmp_seq)*100) @@ -162,3 +170,7 @@ func Ping(domain string, PS int) { fmt.Printf("rtt min/avg/max/mdev = %.3f/%.3f/%.3f ms", min_lan, avg_lan, max_lan) } + +func foot() { + +} diff --git a/goping/ping_test.go b/goping/ping_test.go index c42fb02..691771e 100644 --- a/goping/ping_test.go +++ b/goping/ping_test.go @@ -1,9 +1,19 @@ package goping import ( + "fmt" + "os" + "os/signal" "testing" ) +func TestSign(tt *testing.T) { + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt, os.Kill) + + s := <-c + fmt.Println("Got signal:", s) +} func TestPing(tt *testing.T) { //if len(os.Args) < 3 { // fmt.Printf("Param domain |data package Sizeof|trace times\n Ex: ./Ping www.so.com 100 4\n") @@ -19,6 +29,6 @@ func TestPing(tt *testing.T) { // fmt.Println("you need input correct Counts") // os.Exit(1) //} - Ping("www.baidu.com", 48, 5) + Ping("www.baidu.com", 48) //Ping("www.baidu.com", 48, 5) } diff --git a/pong.go b/pong.go index cc75a8c..bdc7ded 100644 --- a/pong.go +++ b/pong.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "os" + "os/signal" "pong/dial" "pong/goping" "strconv" @@ -21,6 +22,13 @@ pong -a www.baidu.com -p 443 -k tcp -t 3 ` func main() { + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt, os.Kill) + + s := <-c + fmt.Println("Got signal:", s) +} +func main1() { address := flag.String("a", "", "domain or ip address") port := flag.Int("p", 0, "port") protocol := flag.String("k", "tcp", "protocol kind") diff --git a/readme.md b/readme.md index 59b8fe0..120faef 100644 --- a/readme.md +++ b/readme.md @@ -9,12 +9,12 @@ pong -a www.baidu.com -p 443 -k tcp -t 3 ## build cd /root rm -rf pong -git clone https://sre:N7q5BcbQrjpEav_iRCKBta_pVyFhUE_V@git.sre.ink/sre/pong.git +git clone https://git.sre.ink/sre/pong.git cd pong CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on GOPROXY="https://goproxy.cn,direct" go build -v -a -o pong pong.go rm -rf /usr/bin/pong mv pong /usr/bin/ -pong www.baidu.com +pong www.baidu.com 443