日志打印时间
This commit is contained in:
parent
58ca7e22f7
commit
538254f1ba
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -47,24 +48,24 @@ func ProcessDNSUpdateForDomain(key string, Domain string, rrid string, rrhost st
|
|||||||
// 更新DNS
|
// 更新DNS
|
||||||
response, err := PerformDNSUpdate(key, Domain, rrid, rrhost, rrvalue)
|
response, err := PerformDNSUpdate(key, Domain, rrid, rrhost, rrvalue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("获取 DNS 记录失败:", err)
|
log.Println("获取 DNS 记录失败:", err)
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// 打印完整 JSON 数据
|
// 打印完整 JSON 数据
|
||||||
responseJson, err := json.MarshalIndent(response, "", " ")
|
responseJson, err := json.MarshalIndent(response, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("JSON 格式化失败:", err)
|
log.Println("JSON 格式化失败:", err)
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
fmt.Println(string(responseJson))
|
fmt.Println(string(responseJson))
|
||||||
|
|
||||||
// 判断 Code 字段是否表示成功
|
// 判断 Code 字段是否表示成功
|
||||||
if response.Reply.Code == 300 {
|
if response.Reply.Code == 300 {
|
||||||
fmt.Println("DNS 记录更新成功!")
|
log.Println("DNS 记录更新成功!")
|
||||||
return 0
|
return 0
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("DNS 记录更新失败,错误代码:", response.Reply.Code)
|
log.Println("DNS 记录更新失败,错误代码:", response.Reply.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
20
main.go
20
main.go
@ -3,7 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -71,13 +71,13 @@ func getIPv6Addresses() (map[string][]net.IP, error) {
|
|||||||
func pppoe_interface_ipv6(_interface string) string {
|
func pppoe_interface_ipv6(_interface string) string {
|
||||||
addresses, err := getIPv6Addresses()
|
addresses, err := getIPv6Addresses()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("获取 IPv6 地址失败: %v\n", err)
|
log.Printf("获取 IPv6 地址失败: %v\n", err)
|
||||||
return "NULL"
|
return "NULL"
|
||||||
}
|
}
|
||||||
|
|
||||||
//fmt.Println("IPv6 地址列表:")
|
//fmt.Println("IPv6 地址列表:")
|
||||||
for iface, ips := range addresses {
|
for iface, ips := range addresses {
|
||||||
//fmt.Printf("Interface: %s\n", iface)
|
//log.Printf("Interface: %s\n", iface)
|
||||||
if iface == _interface {
|
if iface == _interface {
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
addrType := classifyIPv6(ip)
|
addrType := classifyIPv6(ip)
|
||||||
@ -138,12 +138,12 @@ func Loop() {
|
|||||||
Now_ipv6_addr = pppoe_interface_ipv6(_interface)
|
Now_ipv6_addr = pppoe_interface_ipv6(_interface)
|
||||||
|
|
||||||
if Now_ipv6_addr != Domain_ipv6_addr {
|
if Now_ipv6_addr != Domain_ipv6_addr {
|
||||||
fmt.Printf("域名解析地址: %s\n", Domain_ipv6_addr)
|
log.Printf("域名解析地址: %s\n", Domain_ipv6_addr)
|
||||||
fmt.Printf("当前地址: %s\n", Now_ipv6_addr)
|
log.Printf("当前地址: %s\n", Now_ipv6_addr)
|
||||||
fmt.Printf("域名解析地址与现在地址不相等!!!\n")
|
log.Printf("域名解析地址与现在地址不相等!!!\n")
|
||||||
|
|
||||||
RecordID := FetchSubdomainRecord(key, Domain, Subdomain)
|
RecordID := FetchSubdomainRecord(key, Domain, Subdomain)
|
||||||
fmt.Printf("RecordID:%s\n", RecordID)
|
log.Printf("RecordID:%s\n", RecordID)
|
||||||
if RecordID != "NULL" {
|
if RecordID != "NULL" {
|
||||||
rrid := RecordID
|
rrid := RecordID
|
||||||
rrhost := strings.Split(Subdomain, ".")[0] // 获取子域名前缀 v6
|
rrhost := strings.Split(Subdomain, ".")[0] // 获取子域名前缀 v6
|
||||||
@ -155,9 +155,9 @@ func Loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("域名解析地址: %s\n", Domain_ipv6_addr)
|
log.Printf("域名解析地址: %s\n", Domain_ipv6_addr)
|
||||||
fmt.Printf("当前地址: %s\n", Now_ipv6_addr)
|
log.Printf("当前地址: %s\n", Now_ipv6_addr)
|
||||||
fmt.Printf("域名解析地址与现在地址相等,无需处理!!!\n")
|
log.Printf("域名解析地址与现在地址相等,无需处理!!!\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -69,21 +70,21 @@ func FetchSubdomainRecord(key string, domain string, Subdomain string) string {
|
|||||||
// 获取 DNS 记录
|
// 获取 DNS 记录
|
||||||
response, err := RetrieveDNSRecords(key, domain)
|
response, err := RetrieveDNSRecords(key, domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("获取 DNS 记录失败:", err)
|
log.Println("获取 DNS 记录失败:", err)
|
||||||
return "NULL"
|
return "NULL"
|
||||||
}
|
}
|
||||||
|
|
||||||
// 打印完整 JSON 数据
|
// 打印完整 JSON 数据
|
||||||
_, err = json.MarshalIndent(response, "", " ")
|
_, err = json.MarshalIndent(response, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("JSON 格式化失败:", err)
|
log.Println("JSON 格式化失败:", err)
|
||||||
return "NULL"
|
return "NULL"
|
||||||
}
|
}
|
||||||
|
|
||||||
// 只获取指定子域名的信息
|
// 只获取指定子域名的信息
|
||||||
for _, record := range response.Reply.ResourceRecords {
|
for _, record := range response.Reply.ResourceRecords {
|
||||||
if record.Host == Subdomain {
|
if record.Host == Subdomain {
|
||||||
fmt.Printf("RecordID: %s, Host: %s, Type: %s, Value: %s, TTL: %s, Distance: %s\n",
|
log.Printf("RecordID: %s, Host: %s, Type: %s, Value: %s, TTL: %s, Distance: %s\n",
|
||||||
record.RecordID, record.Host, record.Type, record.Value, record.TTL, parseDistance(record.Distance))
|
record.RecordID, record.Host, record.Type, record.Value, record.TTL, parseDistance(record.Distance))
|
||||||
|
|
||||||
return record.RecordID
|
return record.RecordID
|
||||||
|
Loading…
x
Reference in New Issue
Block a user