Skip to content

Commit

Permalink
v0.0.3 - 修改ping命令识别错误的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
spiritLHLS committed Jul 3, 2024
1 parent 3cd1b82 commit 44eeba3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package model

import "time"

const PingTestVersion = "v0.0.2"
const PingTestVersion = "v0.0.3"

var EnableLoger = false

Expand Down
5 changes: 2 additions & 3 deletions pt/pt.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ func pingServerByGolang(server *model.Server, wg *sync.WaitGroup) {
totalRtt += duration
}
}
fmt.Println(totalRtt.Milliseconds())
server.Avg = totalRtt / time.Duration(pingCount)
server.Avg = totalRtt / time.Duration(float64(pingCount)*float64(time.Millisecond))
}

func pingServerByCMD(server *model.Server, wg *sync.WaitGroup) {
Expand Down Expand Up @@ -165,7 +164,7 @@ func pingServerByCMD(server *model.Server, wg *sync.WaitGroup) {
pingServerByGolang(server, wg)
return
} else {
server.Avg = time.Duration(avgTime)
server.Avg = time.Duration(avgTime * float64(time.Millisecond))
}
}

Expand Down
21 changes: 21 additions & 0 deletions pt/t.go_back
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package pt

import (
"fmt"
"strconv"
"strings"
"time"
)

func TTT() {
output := "PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.\n64 bytes from 1.1.1.1: icmp_seq=1 ttl=58 time=0.944 ms"
var avgTime float64
lines := strings.Split(output, "\n")
if len(lines) >= 2 {
matches := strings.Split(lines[1], "time=")
if len(matches) >= 2 {
avgTime, _ = strconv.ParseFloat(strings.TrimSpace(strings.ReplaceAll(matches[1], "ms", "")), 64)
}
}
fmt.Println(time.Duration(avgTime ))
}
7 changes: 7 additions & 0 deletions pt/t_test.go_back
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package pt

import "testing"

func TestTT(t *testing.T) {
TTT()
}

0 comments on commit 44eeba3

Please sign in to comment.