I
I
Ilya2017-10-20 04:41:15
go
Ilya, 2017-10-20 04:41:15

How to ping an address on the local network?

How can I ping an address on the local network in GO?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Johnny Smith, 2017-10-20
@Rimush

It is not possible to do this in the standard library, you can use this: https://github.com/tatsushid/go-fastping
Note that sending ICMP packets requires root privileges
https://godoc.org/golang.org/x/net/ icmp
https://en.wikipedia.org/wiki/Internet_Control_Mes...
this is not a 100% method to ping other servers because admins often disable ping due to security reasons

out, _ := exec.Command("ping", "192.168.0.111", "-c 5", "-i 3", "-w 10").Output()
if strings.Contains(string(out), "Destination Host Unreachable") {
    fmt.Println("TANGO DOWN")
} else {
    fmt.Println("IT'S ALIVEEE")
}

let me know if it was helpful

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question