From b08b3e465138912e14bf69e68ab49599cb1970b4 Mon Sep 17 00:00:00 2001 From: kurushmal <137996547+ritascarlet@users.noreply.github.com> Date: Sat, 6 Dec 2025 04:59:46 -0800 Subject: [PATCH] Update ipregion.sh --- ipregion.sh | 49 +++++++++++++++++-------------------------------- 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/ipregion.sh b/ipregion.sh index 8734552..bcc7541 100644 --- a/ipregion.sh +++ b/ipregion.sh @@ -924,47 +924,32 @@ get_registered_country() { get_server_country() { local ip_version="$1" - local response country_code country_name + local response country_code - # Используем Cloudflare как основной источник (быстрый и надежный) - response=$(make_request GET "https://speed.cloudflare.com/meta" --ip-version "$ip_version") - - if [[ -n "$response" && "$response" != *"error"* ]]; then - country_code=$(process_json "$response" ".country") - if [[ -n "$country_code" && "$country_code" != "null" ]]; then - echo "$country_code" - return - fi + # 1. ipapi.co — самый стабильный и не ебет мозг + response=$(make_request GET "https://ipapi.co/json" --ip-version "$ip_version") + country_code=$(process_json "$response" ".country_code") + + if [[ -n "$country_code" && "$country_code" != "null" ]]; then + echo "$country_code" + return fi - # Если Cloudflare не сработал, пробуем MaxMind + # 2. MaxMind — fallback response=$(make_request GET "https://geoip.maxmind.com/geoip/v2.1/city/me" \ --header "Referer: https://www.maxmind.com" \ --ip-version "$ip_version") - - if [[ -n "$response" && "$response" != *"error"* ]]; then - country_code=$(process_json "$response" ".country.iso_code") - if [[ -n "$country_code" && "$country_code" != "null" ]]; then - echo "$country_code" - return - fi + country_code=$(process_json "$response" ".country.iso_code") + + if [[ -n "$country_code" && "$country_code" != "null" ]]; then + echo "$country_code" + return fi - # Если и MaxMind не сработал, пробуем IPAPI.co - response=$(make_request GET "https://ipapi.co/json" --ip-version "$ip_version") - - if [[ -n "$response" && "$response" != *"error"* ]]; then - country_code=$(process_json "$response" ".country_code") - if [[ -n "$country_code" && "$country_code" != "null" ]]; then - echo "$country_code" - return - fi - fi - - # Если ничего не сработало echo "Unknown" } + get_iata_location() { local iata_code="$1" local url="https://www.air-port-codes.com/api/v1/single" @@ -1997,7 +1982,7 @@ main() { discover_external_ips get_asn - + # Определяем страну сервера if [[ -n "$EXTERNAL_IPV4" ]]; then SERVER_COUNTRY=$(get_server_country 4) @@ -2006,7 +1991,7 @@ main() { else SERVER_COUNTRY="Unknown" fi - + log "$LOG_INFO" "Server country detected: $SERVER_COUNTRY" case "$GROUPS_TO_SHOW" in