Browse Source

Add PUBLIC_IP_SERVICE to netmaker (server).

cameronts 3 years ago
parent
commit
9e5e1b24b4
1 changed files with 11 additions and 0 deletions
  1. 11 0
      servercfg/serverconf.go

+ 11 - 0
servercfg/serverconf.go

@@ -2,6 +2,7 @@ package servercfg
 
 import (
 	"errors"
+	"fmt"
 	"io"
 	"net/http"
 	"os"
@@ -427,7 +428,16 @@ func GetPublicIP() (string, error) {
 	var err error
 
 	iplist := []string{"https://ip.server.gravitl.com", "https://ifconfig.me", "https://api.ipify.org", "https://ipinfo.io/ip"}
+	publicIpService := os.Getenv("PUBLIC_IP_SERVICE")
+	if publicIpService != "" {
+		fmt.Println("User provided public IP service is", publicIpService)
+
+		// prepend the user-specified service so it's checked first
+		iplist = append([]string{publicIpService}, iplist...)
+	}
+
 	for _, ipserver := range iplist {
+		fmt.Println("Running public IP check with service", ipserver)
 		client := &http.Client{
 			Timeout: time.Second * 10,
 		}
@@ -442,6 +452,7 @@ func GetPublicIP() (string, error) {
 				continue
 			}
 			endpoint = string(bodyBytes)
+			fmt.Println("Public IP address is", endpoint)
 			break
 		}
 	}