mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-12-18 05:04:40 +03:00
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>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user