-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
50 lines (46 loc) · 911 Bytes
/
main.go
File metadata and controls
50 lines (46 loc) · 911 Bytes
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
package main
import (
"ipn/config"
"ipn/ip"
"ipn/mail"
"log"
"os"
"github.com/robfig/cron/v3"
)
func main() {
if config.GetConfig().EnableCron {
c := cron.New()
_, err := c.AddFunc(config.GetConfig().CronExp, check)
if err != nil {
log.Fatalln(err)
}
c.Start()
log.Println("定时任务启动成功")
var block chan struct{} //nil channel
<-block
} else {
check()
}
}
func check() {
// 获取旧IP
old_ip, err := ip.ReadOldIP()
if err != nil && !os.IsNotExist(err) {
log.Fatalln(err)
}
// 获取当前IP
curr_ip, err := ip.GetIPInfo()
if err != nil {
log.Fatalln(err)
}
log.Println(*curr_ip)
if old_ip == nil || *curr_ip != *old_ip {
log.Println("发现IP变更")
mail.SendIP(*curr_ip)
} else if config.GetConfig().AlwaysSend {
log.Println("未发现IP变更,强制发送邮件")
mail.SendIP(*curr_ip)
} else {
log.Println("未发现IP变更")
}
}