-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdoc.go
72 lines (58 loc) · 1.83 KB
/
doc.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*Package kping implements large scale & high performance ICMP flood ping.
It can send up to 1024 ICMP packets in one system call (sendmmsg), and provides two methods for receiving packets quickly: batch, afpacket.
The simplest example:
// Create a new Pinger
pinger, err := NewPinger("10.0.0.1", 100, 10, 1*time.Minute, 100*time.Millisecond)
if err != nil {
logger.Fatalln(err)
}
// Add IP addresses to Pinger
if err := pinger.AddIPs([]string{"114.114.114.114", "8.8.8.8"}); err != nil {
logger.Fatalln(err)
}
// Run !
statistics, err : = pinger.Run()
if err != nil {
logger.Fatalln(err)
}
// Print result
for ip, statistic := range statistics {
fmt.Printf("%s: %v\n", ip, statistic)
}
You can customize and optimize the send & receive options based on your system:
// Create a new Pinger
pinger, err := NewPinger("10.0.0.1", 100, 10, 1*time.Minute, 100*time.Millisecond)
if err != nil {
logger.Fatalln(err)
}
// Set send options
if sendOpts, err := SendOptions(1024, 10*1024*1024, 30, 100*time.Second, 20*time.Millsecond); err != nil{
logger.Fatalln(err)
} else if err := pinger.SetOptions(sendOpts); err != nil {
logger.Fatalln(err)
}
// Set Recv mode: afpacket | batch
if err := pinger.SetRecvMode("afpacket"); err != nil{
logger.Fatalln(err)
}
// Set afpacket recv mode options
if recvOpts, err := AfPacketRecvOptions(2, 256, 128, "eth1", 100*time.Millsecond); err != nil{
logger.Fatalln(err)
} else if err := pinger.SetOptions(recvOpts) {
logger.Fatalln(err)
}
// Add IP addresses to Pinger
if err := pinger.AddIPs([]string{"114.114.114.114", "8.8.8.8"}); err != nil {
logger.Fatalln(err)
}
// Run !
statistics, err : = pinger.Run()
if err != nil {
logger.Fatalln(err)
}
// Print result
for ip, statistic := range statistics {
fmt.Printf("%s: %v\n", ip, statistic)
}
*/
package kping