mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-20 12:04:23 +08:00
Add PUBLIC_IP_SERVICE to netmaker (server).
This commit is contained in:
parent
fc73a18860
commit
9e5e1b24b4
1 changed files with 11 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue