feat: custom ip api (#100)

* feat: custom ip api

feat: add switch for nat and query
Co-authored-by: ChrisKim <[email protected]>

* remove dash.cloudflare

---------

Co-authored-by: ChrisKim <[email protected]>
Co-authored-by: naiba <[email protected]>
This commit is contained in:
UUBulb
2024-11-26 21:29:00 +08:00
committed by GitHub
co-authored by ChrisKim naiba
parent c0de2a8aff
commit bc31032ca8
3 changed files with 37 additions and 3 deletions
+13 -3
View File
@@ -15,9 +15,11 @@ import (
var (
cfList = []string{
"https://blog.cloudflare.com/cdn-cgi/trace",
"https://dash.cloudflare.com/cdn-cgi/trace",
"https://hostinger.com/cdn-cgi/trace",
"https://ahrefs.com/cdn-cgi/trace",
"https://developers.cloudflare.com/cdn-cgi/trace",
}
CustomEndpoints []string
GeoQueryIP, CachedCountryCode string
GeoQueryIPChanged bool = true
httpClientV4 = util.NewSingleStackHTTPClient(time.Second*20, time.Second*5, time.Second*10, false)
@@ -32,11 +34,19 @@ func FetchIP(useIPv6CountryCode bool) *pb.GeoIP {
var ipv4, ipv6 string
go func() {
defer wg.Done()
ipv4 = fetchIP(cfList, false)
if len(CustomEndpoints) > 0 {
ipv4 = fetchIP(CustomEndpoints, false)
} else {
ipv4 = fetchIP(cfList, false)
}
}()
go func() {
defer wg.Done()
ipv6 = fetchIP(cfList, true)
if len(CustomEndpoints) > 0 {
ipv6 = fetchIP(CustomEndpoints, true)
} else {
ipv6 = fetchIP(cfList, true)
}
}()
wg.Wait()