-
Notifications
You must be signed in to change notification settings - Fork 0
/
main1.txt
54 lines (43 loc) · 1012 Bytes
/
main1.txt
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
package main
import (
"fmt"
"net"
"os"
"time"
fastping "github.com/tatsushid/go-fastping"
)
func main() {
//type struct of type []ipList{} with fields of ip string and pingSuccess bool
// type ipAddress struct {
// ip string
// pingSuccess bool
// }
var ipmap map[string]bool
ipmap = make(map[string]bool)
ipList := []string(os.Args[1:])
p := fastping.NewPinger()
//Get all the args and put them into a slice
//range loop through the slice and resolve each ip address
for _, v := range ipList {
ra, err := net.ResolveIPAddr("ip4:icmp", v)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
ipmap[ra.String()] = false
p.AddIPAddr(ra)
}
p.OnRecv = func(addr *net.IPAddr, rtt time.Duration) {
fmt.Printf("IP Addr: %s receive, RTT: %v\n", addr.String(), rtt)
fmt.Println("success!")
ipmap[addr.String()] = true
}
p.OnIdle = func() {
fmt.Println("finish")
fmt.Println(ipmap)
}
err := p.Run()
if err != nil {
fmt.Println(err)
}
}