mirror of
				https://github.com/taigrr/godns
				synced 2025-01-18 04:03:25 -08:00 
			
		
		
		
	add IPv6 support for Cloudflare
This commit is contained in:
		
							parent
							
								
									290f6faf60
								
							
						
					
					
						commit
						ad7fb64aa1
					
				
							
								
								
									
										30
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								README.md
									
									
									
									
									
								
							@ -106,10 +106,38 @@ Usage of ./godns:
 | 
				
			|||||||
* password: Password of your account.
 | 
					* password: Password of your account.
 | 
				
			||||||
* login_token: API token of your account.
 | 
					* login_token: API token of your account.
 | 
				
			||||||
* domains: Domains list, with your sub domains.
 | 
					* domains: Domains list, with your sub domains.
 | 
				
			||||||
* ip_url: A site helps you to get your public IP address.
 | 
					* ip_url: A site helps you to get your public IPv4 IP address.
 | 
				
			||||||
 | 
					* ipv6_url: A site helps you to get your public IPv6 address.
 | 
				
			||||||
 | 
					* ip_type: To configure GoDNS under IPv4 mode or IPv6 mode, available values are: `IPv4`, `IPv6`.
 | 
				
			||||||
* interval: The interval `seconds` that GoDNS check your public IP.
 | 
					* interval: The interval `seconds` that GoDNS check your public IP.
 | 
				
			||||||
* socks5_proxy: Socks5 proxy server.
 | 
					* socks5_proxy: Socks5 proxy server.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## IPv6 support
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Supported provider(s):
 | 
				
			||||||
 | 
					* Cloudflare
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					To enable the `IPv6` mode of GoDNS, you only need two steps:
 | 
				
			||||||
 | 
					* Set the `ip_type` as `IPv6`, and make sure the `ipv6_url` is configured.
 | 
				
			||||||
 | 
					* Add one `AAAA` record to your provider.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					For example:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  "domains": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "domain_name": "example.com",
 | 
				
			||||||
 | 
					      "sub_domains": [
 | 
				
			||||||
 | 
					        "ipv6"
 | 
				
			||||||
 | 
					      ]
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "ipv6_url": "https://api-ipv6.ip.sb/ip",
 | 
				
			||||||
 | 
					  "ip_type": "IPV6"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Config example for Cloudflare
 | 
					### Config example for Cloudflare
 | 
				
			||||||
 | 
					
 | 
				
			||||||
For Cloudflare, you need to provide the email & Global API Key as password (or to use the API token) and config all the domains & subdomains.
 | 
					For Cloudflare, you need to provide the email & Global API Key as password (or to use the API token) and config all the domains & subdomains.
 | 
				
			||||||
 | 
				
			|||||||
@ -19,6 +19,8 @@
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  ],
 | 
					  ],
 | 
				
			||||||
  "ip_url": "https://myip.biturl.top",
 | 
					  "ip_url": "https://myip.biturl.top",
 | 
				
			||||||
 | 
					  "ipv6_url": "https://api-ipv6.ip.sb/ip",
 | 
				
			||||||
 | 
					  "ip_type": "IPv4",
 | 
				
			||||||
  "interval": 300,
 | 
					  "interval": 300,
 | 
				
			||||||
  "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36",
 | 
					  "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36",
 | 
				
			||||||
  "ip_interface": "eth0",
 | 
					  "ip_interface": "eth0",
 | 
				
			||||||
 | 
				
			|||||||
@ -9,6 +9,7 @@ import (
 | 
				
			|||||||
	"log"
 | 
						"log"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"runtime/debug"
 | 
						"runtime/debug"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/TimothyYe/godns"
 | 
						"github.com/TimothyYe/godns"
 | 
				
			||||||
@ -194,8 +195,16 @@ func (handler *Handler) getDNSRecords(zoneID string) []DNSRecord {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	var empty []DNSRecord
 | 
						var empty []DNSRecord
 | 
				
			||||||
	var r DNSRecordResponse
 | 
						var r DNSRecordResponse
 | 
				
			||||||
 | 
						var recordType string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	req, client := handler.newRequest("GET", "/zones/"+zoneID+"/dns_records?type=A", nil)
 | 
						if handler.Configuration.IPType == "" || strings.ToUpper(handler.Configuration.IPType) == godns.IPV4 {
 | 
				
			||||||
 | 
							recordType = "A"
 | 
				
			||||||
 | 
						} else if strings.ToUpper(handler.Configuration.IPType) == godns.IPV6 {
 | 
				
			||||||
 | 
							recordType = "AAAA"
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						log.Println("Querying records with type:", recordType)
 | 
				
			||||||
 | 
						req, client := handler.newRequest("GET", fmt.Sprintf("/zones/"+zoneID+"/dns_records?type=%s", recordType), nil)
 | 
				
			||||||
	resp, err := client.Do(req)
 | 
						resp, err := client.Do(req)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Println("Request error:", err.Error())
 | 
							log.Println("Request error:", err.Error())
 | 
				
			||||||
 | 
				
			|||||||
@ -37,7 +37,7 @@ type Settings struct {
 | 
				
			|||||||
	Socks5Proxy string   `json:"socks5_proxy"`
 | 
						Socks5Proxy string   `json:"socks5_proxy"`
 | 
				
			||||||
	Notify      Notify   `json:"notify"`
 | 
						Notify      Notify   `json:"notify"`
 | 
				
			||||||
	IPInterface string   `json:"ip_interface"`
 | 
						IPInterface string   `json:"ip_interface"`
 | 
				
			||||||
	Mode        string   `json:"mode"`
 | 
						IPType      string   `json:"ip_type"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// LoadSettings -- Load settings from config file
 | 
					// LoadSettings -- Load settings from config file
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										10
									
								
								utils.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								utils.go
									
									
									
									
									
								
							@ -88,13 +88,12 @@ func GetIPFromInterface(configuration *Settings) (string, error) {
 | 
				
			|||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//the code is not ready for updating the 'AAAA' record
 | 
					 | 
				
			||||||
		if isIPv4(ip.String()) {
 | 
							if isIPv4(ip.String()) {
 | 
				
			||||||
			if strings.ToUpper(configuration.Mode) == IPV4 {
 | 
								if strings.ToUpper(configuration.IPType) == IPV4 {
 | 
				
			||||||
				continue
 | 
									continue
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			if configuration.Mode != IPV6 {
 | 
								if configuration.IPType != IPV6 {
 | 
				
			||||||
				continue
 | 
									continue
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -137,7 +136,7 @@ func GetHttpClient(configuration *Settings) *http.Client {
 | 
				
			|||||||
func GetCurrentIP(configuration *Settings) (string, error) {
 | 
					func GetCurrentIP(configuration *Settings) (string, error) {
 | 
				
			||||||
	var err error
 | 
						var err error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if configuration.IPUrl != "" {
 | 
						if configuration.IPUrl != "" || configuration.IPV6Url != "" {
 | 
				
			||||||
		ip, err := GetIPOnline(configuration)
 | 
							ip, err := GetIPOnline(configuration)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			log.Println("get ip online failed. Fallback to get ip from interface if possible.")
 | 
								log.Println("get ip online failed. Fallback to get ip from interface if possible.")
 | 
				
			||||||
@ -163,7 +162,6 @@ func GetIPOnline(configuration *Settings) (string, error) {
 | 
				
			|||||||
	client := &http.Client{}
 | 
						client := &http.Client{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if configuration.Socks5Proxy != "" {
 | 
						if configuration.Socks5Proxy != "" {
 | 
				
			||||||
 | 
					 | 
				
			||||||
		log.Println("use socks5 proxy:" + configuration.Socks5Proxy)
 | 
							log.Println("use socks5 proxy:" + configuration.Socks5Proxy)
 | 
				
			||||||
		dialer, err := proxy.SOCKS5("tcp", configuration.Socks5Proxy, nil, proxy.Direct)
 | 
							dialer, err := proxy.SOCKS5("tcp", configuration.Socks5Proxy, nil, proxy.Direct)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
@ -179,7 +177,7 @@ func GetIPOnline(configuration *Settings) (string, error) {
 | 
				
			|||||||
	var response *http.Response
 | 
						var response *http.Response
 | 
				
			||||||
	var err error
 | 
						var err error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if configuration.Mode == IPV4 {
 | 
						if configuration.IPType == "" || configuration.IPType == IPV4 {
 | 
				
			||||||
		response, err = client.Get(configuration.IPUrl)
 | 
							response, err = client.Get(configuration.IPUrl)
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		response, err = client.Get(configuration.IPV6Url)
 | 
							response, err = client.Get(configuration.IPV6Url)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user