add nic check

This commit is contained in:
Jay 2018-09-10 10:44:23 +08:00
parent 2203303968
commit 4d63b93edb
3 changed files with 22 additions and 0 deletions

View File

@ -1,3 +1,4 @@
interface: eth0
domains:
- name: domain.name
subdomain:

20
main.go
View File

@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"log"
"net"
"net/http"
"regexp"
"time"
@ -42,6 +43,25 @@ func main() {
newR53()
config = setting.LoadConfig(confpath)
fmt.Println(config)
// wait nic
for {
nics, err := net.Interfaces()
if err != nil {
log.Fatal(err)
}
nicFlag := false
for _, v := range nics {
if v.Name == config.NIC {
nicFlag = true
}
}
if nicFlag == true {
break
}
time.Sleep(time.Second * 5)
}
ip = getMyIP()
if ok, err := checkIP(ip); err != nil || !ok {
println("ip check fail")

View File

@ -11,6 +11,7 @@ import (
)
type Config struct {
NIC string `yaml:"interface"`
Domains []struct {
Name string `yaml:"name"`
Sub []string `yaml:"subdomain,flow"`