zabov/01.dnscheck.go

38 lines
548 B
Go
Raw Normal View History

2020-10-08 16:14:07 -04:00
package main
import (
"fmt"
"net/http"
"time"
)
//NetworkUp tells the system if the network is up or not
var NetworkUp bool
func checkNetworkUp() bool {
// RFC2606 test domain, should always work, unless internet is down.
_, err := http.Get("http://example.com")
if err != nil {
return false
}
return true
}
func checkNetworkUpThread() {
ticker := time.NewTicker(2 * time.Minute)
for range ticker.C {
NetworkUp = checkNetworkUp()
}
}
func init() {
fmt.Println("Network Checker starting....")
go checkNetworkUpThread()
}