Skip to content

Commit 2a69a8b

Browse files
committed
Initial version
1 parent 7ec382c commit 2a69a8b

10 files changed

+974
-0
lines changed

Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
APPNAME=mping
2+
3+
all:
4+
CGO_ENABLED=0 go build -o $(APPNAME) cmd/main.go
5+
6+
clean:
7+
go clean
8+
rm -f $(APPNAME)

cmd/main.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"net/netip"
6+
7+
"github.com/drgkaleda/go-multiping"
8+
)
9+
10+
func main() {
11+
data := multiping.NewPingData()
12+
mp, err := multiping.New(false)
13+
if err != nil {
14+
log.Println(err)
15+
return
16+
}
17+
18+
data.Add(netip.MustParseAddr("1.1.1.1"))
19+
data.Add(netip.MustParseAddr("8.8.8.8"))
20+
data.Add(netip.MustParseAddr("4.4.4.4"))
21+
// For unknown reasons this IP reports dups. Usefull for testing
22+
data.Add(netip.MustParseAddr("74.3.163.56"))
23+
24+
for i := 0; i < 100; i++ {
25+
mp.Ping(data)
26+
27+
data.Iterate(func(ip netip.Addr, val multiping.PingStats) {
28+
log.Println(ip, val.Valid(), val.Latency(), val.Loss(), val.Duplicate())
29+
})
30+
}
31+
}

defs.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package multiping
2+
3+
import "net/netip"
4+
5+
const (
6+
timeSliceLength = 8
7+
trackerLength = 8
8+
protocolICMP = 1
9+
protocolIPv6ICMP = 58
10+
)
11+
12+
type ProtocolVersion int
13+
14+
const (
15+
ProtocolIpv4 = ProtocolVersion(4)
16+
ProtocolIpv6 = ProtocolVersion(6)
17+
)
18+
19+
var (
20+
ipv4Proto = map[string]string{"icmp": "ip4:icmp", "udp": "udp4"}
21+
ipv6Proto = map[string]string{"icmp": "ip6:ipv6-icmp", "udp": "udp6"}
22+
)
23+
24+
type packet struct {
25+
bytes []byte
26+
nbytes int
27+
ttl int
28+
proto ProtocolVersion
29+
src netip.Addr
30+
}

go.mod

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module github.com/drgkaleda/go-multiping
2+
3+
go 1.19
4+
5+
require golang.org/x/net v0.1.0
6+
7+
require golang.org/x/sys v0.1.0 // indirect

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0=
2+
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
3+
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
4+
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

0 commit comments

Comments
 (0)