-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathddns.go
More file actions
73 lines (58 loc) · 1.26 KB
/
Copy pathddns.go
File metadata and controls
73 lines (58 loc) · 1.26 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"flag"
"fmt"
"os"
"log"
"strings"
"time"
"github.com/kardianos/osext"
)
const (
INTERVAL = 5 //Minute
)
var (
config Settings
configPath = flag.String("c", "conf/app.yml", "Specify a configuration file")
showHelp = flag.Bool("h", false, "Show help")
)
func main() {
flag.Parse()
if *showHelp {
flag.Usage()
return
}
if !strings.HasPrefix(*configPath, "/") {
pwd, _ := osext.ExecutableFolder()
*configPath = fmt.Sprintf("%s%s%s", pwd, "/", *configPath)
}
print(*configPath)
if err := Load(*configPath, &config); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
log.Println(config)
dnsLoop()
}
func dnsLoop() {
for {
currentIP, err := getCurrentIP(config.IPService)
if err != nil {
log.Println(err)
time.Sleep(time.Second * 3)
continue
}
subDomainID, ip := getSubDomain(config.Domain, config.SubDomain, config.Type)
if subDomainID == "" || ip == "" {
fmt.Println("sub_domain:", subDomainID, ip)
continue
}
if len(ip) > 0 && !strings.Contains(currentIP, ip) {
updateIP(config.Domain, subDomainID, config.SubDomain, currentIP, config.Ttl)
} else {
fmt.Println("Current IP is same as domain IP, no need to update...")
}
//Interval is 5 minutes
time.Sleep(time.Minute * INTERVAL)
}
}