Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IPing ¶
type IPing struct {
// contains filtered or unexported fields
}
IPing provide ability to send and receive ICMP packets
func (*IPing) Trace ¶
func (p *IPing) Trace(ipAddr *net.IPAddr, ttl int, timeout time.Duration) (time.Duration, net.Addr, error)
Trace ipAddr with timeout
Example ¶
stop := make(chan bool, 2)
ping := NewPing(stop)
if err := ping.Start(); err != nil {
log.Fatalf("start ping error, %s", err)
}
addr, _ := net.ResolveIPAddr("ip", "example.com")
ttl := 1
for {
if latency, from, err := ping.Trace(addr, ttl, 2*time.Second); err != nil {
if _, ok := err.(*errors.ErrTTLExceed); !ok {
log.Println("timeout")
break
}
log.Printf("%d %+v, %+v", ttl, from, latency)
ttl++
} else {
log.Printf("%d %+v, %+v", ttl, from, latency)
break
}
}
Click to show internal directories.
Click to hide internal directories.