mirror of
https://github.com/taigrr/go-fastping
synced 2025-01-18 05:03:15 -08:00
Option to specify source ip for ping
This commit is contained in:
committed by
Tatsushi Demachi
parent
5bf6f7ec59
commit
a06009512e
@@ -23,7 +23,7 @@ func main() {
|
||||
flag.BoolVar(&useUDP, "udp", false, "use non-privileged datagram-oriented UDP as ICMP endpoints")
|
||||
flag.BoolVar(&useUDP, "u", false, "use non-privileged datagram-oriented UDP as ICMP endpoints (shorthand)")
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintf(os.Stderr, "Usage:\n %s [options] hostname\n\nOptions:\n", os.Args[0])
|
||||
fmt.Fprintf(os.Stderr, "Usage:\n %s [options] hostname [source]\n\nOptions:\n", os.Args[0])
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
flag.Parse()
|
||||
@@ -34,6 +34,11 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
source := ""
|
||||
if flag.NArg() > 1 {
|
||||
source = flag.Arg(1)
|
||||
}
|
||||
|
||||
p := fastping.NewPinger()
|
||||
if useUDP {
|
||||
p.Network("udp")
|
||||
@@ -49,6 +54,10 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if source != "" {
|
||||
p.Source(source)
|
||||
}
|
||||
|
||||
results := make(map[string]*response)
|
||||
results[ra.String()] = nil
|
||||
p.AddIPAddr(ra)
|
||||
|
||||
Reference in New Issue
Block a user