-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
54 lines (45 loc) · 938 Bytes
/
utils.go
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"
)
func FileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}
func GetConnectionStatus() bool {
fmt.Println("checking network connection:")
duration, _ := time.ParseDuration("10s")
conn, err := net.DialTimeout("ip:icmp", "1.1.1.1", duration)
if err != nil {
fmt.Print("error: ")
fmt.Println(err)
fmt.Println("done. \n ")
return false
}
if conn != nil {
fmt.Println("ping 1.1.1.1 .... ok")
} else {
fmt.Println("ping 1.1.1.1 .... fail")
}
conn.Close()
connDNS, errDNS := net.DialTimeout("tcp", "ya.ru:80", duration)
if errDNS != nil {
fmt.Print("error: ")
fmt.Println(errDNS)
fmt.Println("done. \n ")
return false
}
if connDNS != nil {
fmt.Println("dns to ya.ru .... ok")
} else {
fmt.Println("dns to ya.ru .... fail")
}
fmt.Println("done. \n ")
return true
}