diff options
| author | Mikhail Grigorev <sleuthhound@gmail.com> | 2025-07-27 18:24:11 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-27 18:24:11 +0300 |
| commit | 0ad708b1b633d7f7f08c18f9ed358809c9faa8b7 (patch) | |
| tree | 68a7b712cce87430924d5311647b75652f982a8b | |
| parent | 71f13ebcbd1d15eb8d5bd6b88ddb2c96e08a287a (diff) | |
Added list of services for get public IP address (IP v4 and v6) (#3216)
* Fixed get public IP address
* Remove https://ifconfig.io/ip and https://ipinfo.tw/ip
---------
Co-authored-by: Mikhail Grigorev <grigorev_mm@magnit.ru>
| -rw-r--r-- | install.sh | 12 | ||||
| -rw-r--r-- | web/service/server.go | 24 |
2 files changed, 24 insertions, 12 deletions
@@ -7,6 +7,7 @@ yellow='\033[0;33m' plain='\033[0m' cur_dir=$(pwd) +show_ip_service_lists=("https://api.ipify.org" "https://4.ident.me") # check root [[ $EUID -ne 0 ]] && echo -e "${red}Fatal error: ${plain} Please run this script with root privilege \n " && exit 1 @@ -85,10 +86,13 @@ config_after_install() { local existing_hasDefaultCredential=$(/usr/local/x-ui/x-ui setting -show true | grep -Eo 'hasDefaultCredential: .+' | awk '{print $2}') local existing_webBasePath=$(/usr/local/x-ui/x-ui setting -show true | grep -Eo 'webBasePath: .+' | awk '{print $2}') local existing_port=$(/usr/local/x-ui/x-ui setting -show true | grep -Eo 'port: .+' | awk '{print $2}') - local server_ip=$(curl -s --max-time 3 https://api.ipify.org) - if [ -z "$server_ip" ]; then - server_ip=$(curl -s --max-time 3 https://4.ident.me) - fi + + for ip_service_addr in "${show_ip_service_lists[@]}"; do + local server_ip=$(curl -s --max-time 3 ${ip_service_addr} 2>/dev/null) + if [ -n "${server_ip}" ]; then + break + fi + done if [[ ${#existing_webBasePath} -lt 4 ]]; then if [[ "$existing_hasDefaultCredential" == "true" ]]; then diff --git a/web/service/server.go b/web/service/server.go index d0d4bd18..1bd8a55d 100644 --- a/web/service/server.go +++ b/web/service/server.go @@ -234,23 +234,31 @@ func (s *ServerService) GetStatus(lastStatus *Status) *Status { } // IP fetching with caching + showIp4ServiceLists := []string{"https://api.ipify.org", "https://4.ident.me"} + showIp6ServiceLists := []string{"https://api6.ipify.org", "https://6.ident.me"} + if s.cachedIPv4 == "" { - s.cachedIPv4 = getPublicIP("https://api.ipify.org") - if s.cachedIPv4 == "N/A" { - s.cachedIPv4 = getPublicIP("https://4.ident.me") + for _, ip4Service := range showIp4ServiceLists { + s.cachedIPv4 = getPublicIP(ip4Service) + if s.cachedIPv4 != "N/A" { + break + } } } if s.cachedIPv6 == "" && !s.noIPv6 { - s.cachedIPv6 = getPublicIP("https://api6.ipify.org") - if s.cachedIPv6 == "N/A" { - s.cachedIPv6 = getPublicIP("https://6.ident.me") - if s.cachedIPv6 == "N/A" { - s.noIPv6 = true + for _, ip6Service := range showIp6ServiceLists { + s.cachedIPv6 = getPublicIP(ip6Service) + if s.cachedIPv6 != "N/A" { + break } } } + if s.cachedIPv6 == "N/A" { + s.noIPv6 = true + } + status.PublicIP.IPv4 = s.cachedIPv4 status.PublicIP.IPv6 = s.cachedIPv6 |
