Merge pull request #2 from Davoyan/master

This commit is contained in:
Nikita Skryabin 2025-02-24 10:39:33 +03:00 committed by GitHub
parent ca9a4eb2f8
commit 0efda77d42
3 changed files with 752 additions and 75 deletions

View file

@ -1,8 +1,8 @@
# IPRegion 🌍
This is a shell script designed to check how your public IP address is identified by various IP databases. The script queries multiple sources to retrieve the country code associated with your IP, providing a comprehensive overview of how different services interpret your location.
![image](https://i.imgur.com/7Tj4Usc.png)
This shell script is designed to check how your public IP address is identified by various IP databases. The script queries multiple sources to retrieve the country code associated with your IP, providing a comprehensive overview of how different services interpret your location.
![image](https://github.com/vernette/ipregion/blob/master/test_example.jpg?raw=true)
## Features
@ -14,8 +14,8 @@ This is a shell script designed to check how your public IP address is identifie
- and [many](https://github.com/vernette/ipregion/blob/master/ipregion.sh#L6) more!
- **User-Friendly Output**: Displays the results in a clean and formatted manner, showing how each service identifies your IP.
- **Lightweight**: Written in Bash, the script has minimal dependencies, primarily requiring `curl` and `jq` for network requests and JSON parsing.
- **Support for SOCKS proxy** allows running the script through a local SOCKS proxy.
## Dependencies
@ -37,7 +37,12 @@ For other systems, please install `curl` and `jq` manually.
bash <(wget -qO - https://github.com/vernette/ipregion/raw/master/ipregion.sh)
```
Or download the script and run it manually:
To run the script through a local SOCKS proxy on port 40000 (example):
```
bash <(wget -qO - https://github.com/vernette/ipregion/raw/master/ipregion.sh) --socks-port 40000
```
You can download the script and run it manually:
```bash
wget -O https://github.com/vernette/ipregion/raw/master/ipregion.sh
@ -45,10 +50,5 @@ chmod +x ipregion.sh
./ipregion.sh
```
## TODO
- [ ] Add more IP services
- [ ] Add more supported OSes
- [ ] Handle errors when doing network requests
- [ ] Handle service rate limit errors
- [ ] Add IP identification by various sites (Google, TikTok, OpenAI, etc.)

View file

@ -31,6 +31,27 @@
DEPENDENCIES="jq curl"
SOCKS_PORT=""
while [ $# -gt 0 ]; do
case "$1" in
--socks|--socks-port|-s)
SOCKS_PORT="$2"
shift 2
;;
*)
shift
;;
esac
done
if [ -n "$SOCKS_PORT" ]; then
# Устанавливаем прокси для всех запросов curl
export ALL_PROXY="socks5://127.0.0.1:$SOCKS_PORT"
echo "Используем SOCKS-прокси 127.0.0.1:$SOCKS_PORT"
fi
RIPE_DOMAIN="rdap.db.ripe.net"
IPINFO_DOMAIN="ipinfo.io"
IPREGISTRY_DOMAIN="ipregistry.co"
@ -55,13 +76,22 @@ FREEIPAPI_DOMAIN="freeipapi.com"
IPBASE_DOMAIN="ipbase.com"
IP_SB_DOMAIN="ip.sb"
MAXMIND_COM_DOMAIN="maxmind.com"
CLOUDFLARE_DOMAIN="cloudflare.com"
YOUTUBE_DOMAIN="youtube.com"
IPWHODE4_DOMAIN="4.ipwho.de"
CHATGPT="chatgpt.com"
IDENTITY_SERVICES="https://ident.me https://ifconfig.co https://ifconfig.me https://icanhazip.com https://api64.ipify.org"
IDENTITY_SERVICES="https://ident.me https://ifconfig.me https://api64.ipify.org https://4.ipwho.de/ip"
USER_AGENT="Mozilla/5.0 (X11; Linux x86_64; rv:130.0) Gecko/20100101 Firefox/130.0"
COLOR_BOLD_GREEN="\033[1;32;40m"
COLOR_BOLD_CYAN="\033[1;36;40m"
COLOR_BOLD_ORANGE="\033[38;5;214;40m"
COLOR_BOLD_RED="\033[38;5;196;40m"
COLOR_BOLD_GRAY="\033[38;5;238;40m"
COLOR_BOLD_WHITE="\033[38;5;15;40m"
COLOR_RESET="\033[0m"
COLOR_BOLD_GREEN="\033[1;32m"
COLOR_BOLD_CYAN="\033[1;36m"
clear_screen() {
clear
@ -140,14 +170,14 @@ install_dependencies() {
$use_sudo dnf install -y "${missing_packages[@]}"
;;
*)
log_message "ERROR" "Unknown or unsupported distribution: $ID"
log_message "" "Unknown or unsupported distribution: $ID"
exit 1
;;
esac
clear_screen
else
log_message "ERROR" "File /etc/os-release not found, unable to determine distribution"
log_message "" "File /etc/os-release not found, unable to determine distribution"
exit 1
fi
}
@ -161,129 +191,753 @@ get_ipv4() {
hidden_ip="$(printf "%s" "$external_ip" | cut -d'.' -f1-2).***.***"
}
get_ipv6() {
external_ipv6=$(curl -6 -s https://6.ipwho.de/ip)
hidden_ipv6=$(mask_ipv6 "$external_ipv6")
}
mask_ipv6() {
local ipv6="$1"
IFS=":" read -ra segments <<< "$ipv6"
for i in "${!segments[@]}"; do
if (( i > 1 && i < ${#segments[@]} - 2 )); then
segments[i]="****"
fi
done
echo "${segments[*]}" | sed 's/ /:/g'
}
check_service() {
local domain="$1"
local lookup_function="$2"
local lookup_function="$2"
local lookup_function_v6="${3:-null}" # По умолчанию null, если аргумент не передан
printf "\r\033[KChecking: %s" "[$domain]"
result="$($lookup_function)"
results+=("[$COLOR_BOLD_GREEN$domain$COLOR_RESET]${COLOR_RESET}: $result")
# Обработка результата в зависимости от домена
if [[ -n "$result" ]]; then
domain_str="$COLOR_BOLD_GREEN$domain$COLOR_RESET${COLOR_RESET}"
# Рассчитываем, сколько пробелов нужно добавить, чтобы длина строки была 20
padding_length=$((23 - ${#domain} - ${#result} - 2)) # 2 — это для ": " между domain и result
padding=$(printf '%*s' "$padding_length" | tr ' ' '.')
padding="${COLOR_BOLD_GRAY}${padding}${COLOR_RESET}"
result="${COLOR_BOLD_WHITE}${result}${COLOR_RESET}"
if [[ "$lookup_function_v6" == "null" || "$lookup_function_v6" == "" ]]; then
results+=("$domain_str$padding$result")
else
result_v6="$($lookup_function_v6)"
if [[ "$result_v6" == "null" || "$result_v6" == "" ]]; then
results+=("$domain_str$padding$result")
else
results+=("$domain_str$padding$result${COLOR_BOLD_GRAY}........${COLOR_RESET}${COLOR_BOLD_WHITE}$result_v6${COLOR_RESET}")
fi
fi
fi
}
print_results() {
printf "%bResults for IP %b%s%b\n\n" "${COLOR_BOLD_GREEN}" "${COLOR_BOLD_CYAN}" "$hidden_ip" "${COLOR_RESET}"
if [[ -n "$external_ipv6" ]]; then
printf "\n\n%bResults for IP %b%s %s %s%b\n\n" \
"${COLOR_BOLD_GREEN}" "${COLOR_BOLD_CYAN}" "$hidden_ip" "and" "$hidden_ipv6" "${COLOR_RESET}"
printf " Ipv4 Ipv6\n\n"
else
printf "\n\n%bResults for IP %b%s%b\n\n" \
"${COLOR_BOLD_GREEN}" "${COLOR_BOLD_CYAN}" "$hidden_ip" "${COLOR_RESET}"
printf " Ipv4\n\n"
fi
for result in "${results[@]}"; do
printf "%b\n" "$result"
done
printf "\n"
}
ripe_rdap_lookup() {
curl -s https://rdap.db.ripe.net/ip/"$external_ip" | jq -r ".country"
result=$(timeout 3 curl -4 -s https://rdap.db.ripe.net/ip/"$external_ip" | jq -r ".country" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ripe_rdap_lookup_v6() {
result=$(timeout 3 curl -4 -s https://rdap.db.ripe.net/ip/"$external_ipv6" | jq -r ".country" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ipinfo_io_lookup() {
curl -s https://ipinfo.io/widget/demo/"$external_ip" | jq -r ".data.country"
result=$(timeout 3 curl -4 -s https://ipinfo.io/widget/demo/"$external_ip" | jq -r ".data.country" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ipinfo_io_lookup_v6() {
sleep 2
result=$(timeout 3 curl -4 -s https://ipinfo.io/widget/demo/""$external_ipv6"" | jq -r ".data.country" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ipregistry_co_lookup() {
# TODO: Add automatic API key parsing
api_key="sb69ksjcajfs4c"
curl -s "https://api.ipregistry.co/$external_ip?hostname=true&key=$api_key" -H "Origin: https://ipregistry.co" | jq -r ".location.country.code"
result=$(timeout 3 curl -4 -s "https://api.ipregistry.co/$external_ip?hostname=true&key=$api_key" -H "Origin: https://ipregistry.co" | jq -r ".location.country.code" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ipregistry_co_lookup_v6() {
# TODO: Add automatic API key parsing
api_key="sb69ksjcajfs4c"
result=$(timeout 3 curl -4 -s "https://api.ipregistry.co/$external_ipv6?hostname=true&key=$api_key" -H "Origin: https://ipregistry.co" | jq -r ".location.country.code" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
cloudflare_lookup() {
result=$(timeout 3 curl -4 -s "https://www.cloudflare.com/cdn-cgi/trace" | grep loc | cut -d= -f2)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
cloudflare_lookup_v6() {
result=$(timeout 3 curl -6 -s "https://www.cloudflare.com/cdn-cgi/trace" | grep loc | cut -d= -f2)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
youtube_lookup() {
result=$(timeout 3 curl -4 -s "https://www.youtube.com" | grep -oP '"countryCode":"\K\w+')
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
youtube_lookup_v6() {
result=$(timeout 3 curl -6 -s "https://www.youtube.com" | grep -oP '"countryCode":"\K\w+')
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ipapi_com_lookup() {
curl -s "https://ipapi.com/ip_api.php?ip=$external_ip" | jq -r ".country_code"
result=$(timeout 3 curl -4 -s "https://ipapi.com/ip_api.php?ip=$external_ip" | jq -r ".country_code" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ipapi_com_lookup_v6() {
result=$(timeout 3 curl -4 -s "https://ipapi.com/ip_api.php?ip=$external_ipv6" | jq -r ".country_code" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
db_ip_com_lookup() {
curl -s "https://db-ip.com/demo/home.php?s=$external_ip" | jq -r ".demoInfo.countryCode"
result=$(timeout 3 curl -4 -s "https://db-ip.com/demo/home.php?s=$external_ip" | jq -r ".demoInfo.countryCode" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
db_ip_com_lookup_v6() {
result=$(timeout 3 curl -4 -s "https://db-ip.com/demo/home.php?s=$external_ipv6" | jq -r ".demoInfo.countryCode" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ipdata_co_lookup() {
html=$(curl -s "https://ipdata.co")
html=$(timeout 3 curl -4 -s "https://ipdata.co")
api_key=$(printf "%s" "$html" | grep -oP '(?<=api-key=)[a-zA-Z0-9]+')
curl -s -H "Referer: https://ipdata.co" "https://api.ipdata.co/?api-key=$api_key" | jq -r ".country_code"
result=$(timeout 3 curl -4 -s -H "Referer: https://ipdata.co" "https://api.ipdata.co/?api-key=$api_key" | jq -r ".country_code" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ipdata_co_lookup_v6() {
html=$(timeout 3 curl -6 -s "https://ipdata.co")
api_key=$(printf "%s" "$html" | grep -oP '(?<=api-key=)[a-zA-Z0-9]+')
result=$(timeout 3 curl -6 -s -H "Referer: https://ipdata.co" "https://api.ipdata.co/?api-key=$api_key" | jq -r ".country_code" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ipwhois_io_lookup() {
curl -s -H "Referer: https://ipwhois.io" "https://ipwhois.io/widget?ip=$external_ip&lang=en" | jq -r ".country_code"
result=$(timeout 3 curl -4 -s -H "Referer: https://ipwhois.io" "https://ipwhois.io/widget?ip=$external_ip&lang=en" | jq -r ".country_code" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ipwhois_io_lookup_v6() {
result=$(timeout 3 curl -4 -s -H "Referer: https://ipwhois.io" "https://ipwhois.io/widget?ip=$external_ipv6&lang=en" | jq -r ".country_code" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ifconfig_co_lookup() {
curl -s "https://ifconfig.co/country-iso?ip=$external_ip"
result=$(timeout 3 curl -4 -s "https://ifconfig.co/country-iso?ip=$external_ip")
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
whoer_net_lookup() {
curl -s "https://whoer.net/whois?host=$external_ip" | grep "country" | awk 'NR==1 {print $2}'
ifconfig_co_lookup_v6() {
result=$(timeout 3 curl -4 -s "https://ifconfig.co/country-iso?ip=$external_ipv6")
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
whoer_net_lookup() {
result=$(timeout 3 curl -4 -s "https://whoer.net/whois?host=$external_ip" | grep "country" | awk 'NR==1 {print $2}')
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ] || [ "$result" == "ZZ" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
whoer_net_lookup_v6() {
result=$(timeout 3 curl -4 -s "https://whoer.net/whois?host=$external_ipv6" | grep "country" | awk 'NR==1 {print $2}')
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ] || [ "$result" == "ZZ" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ipquery_io_lookup() {
curl -s "https://api.ipquery.io/$external_ip" | jq -r ".location.country_code"
result=$(timeout 3 curl -4 -s "https://api.ipquery.io/$external_ip" | jq -r ".location.country_code" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ipquery_io_lookup_v6() {
result=$(timeout 3 curl -4 -s "https://api.ipquery.io/$external_ipv6" | jq -r ".location.country_code" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
country_is_lookup() {
curl -s "https://api.country.is/$external_ip" | jq -r ".country"
result=$(timeout 3 curl -4 -s "https://api.country.is/$external_ip" | jq -r ".country" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
country_is_lookup_v6() {
result=$(timeout 3 curl -4 -s "https://api.country.is/$external_ipv6" | jq -r ".country" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
cleantalk_org_lookup() {
curl -s "https://api.cleantalk.org/?method_name=ip_info&ip=$external_ip" | jq -r --arg ip "$external_ip" '.data[$ip | tostring].country_code'
result=$(timeout 3 curl -4 -s "https://api.cleantalk.org/?method_name=ip_info&ip=$external_ip" | jq -r --arg ip "$external_ip" '.data[$ip | tostring].country_code' 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
cleantalk_org_lookup_v6() {
result=$(timeout 3 curl -4 -s "https://api.cleantalk.org/?method_name=ip_info&ip=$external_ipv6" | jq -r --arg ip "$external_ip" '.data[$ip | tostring].country_code' 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ip_api_com_lookup() {
curl -s "https://demo.ip-api.com/json/$external_ip" -H "Origin: https://ip-api.com" | jq -r ".countryCode"
result=$(timeout 3 curl -4 -s "https://demo.ip-api.com/json/$external_ip" -H "Origin: https://ip-api.com" | jq -r ".countryCode" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ip_api_com_lookup_v6() {
result=$(timeout 3 curl -4 -s "https://demo.ip-api.com/json/$external_ipv6" -H "Origin: https://ip-api.com" | jq -r ".countryCode" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ipgeolocation_io_lookup() {
curl -s "https://api.ipgeolocation.io/ipgeo?ip=$external_ip" -H "Referer: https://ipgeolocation.io" | jq -r ".country_code2"
result=$(timeout 3 curl -4 -s "https://api.ipgeolocation.io/ipgeo?ip=$external_ip" -H "Referer: https://ipgeolocation.io" | jq -r ".country_code2" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ipapi_co_lookup() {
curl -s "https://ipapi.co/$external_ip/json" | jq -r ".country"
result=$(timeout 3 curl -4 -s "https://ipapi.co/$external_ip/json" | jq -r ".country" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ipapi_co_lookup_v6() {
result=$(timeout 3 curl -4 -s "https://ipapi.co/$external_ipv6/json" | jq -r ".country" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
findip_net_lookup() {
cookie_file=$(mktemp)
html=$(curl -s -c "$cookie_file" "https://findip.net")
request_verification_token=$(printf "%s" "$html" | grep "__RequestVerificationToken" | grep -oP 'value="\K[^"]+')
response=$(curl -s -X POST "https://findip.net" \
response=$(timeout 3 curl -s -X POST "https://findip.net" \
--data-urlencode "__RequestVerificationToken=$request_verification_token" \
--data-urlencode "ip=$external_ip" \
-b "$cookie_file")
rm "$cookie_file"
printf "%s" "$response" | grep -oP 'ISO Code: <span class="text-success">\K[^<]+'
if [ $? -eq 124 ]; then
echo ""
else
printf "%s" "$response" | grep -oP 'ISO Code: <span class="text-success">\K[^<]+'
fi
}
geojs_io_lookup() {
curl -s "https://get.geojs.io/v1/ip/country.json?ip=$external_ip" | jq -r ".[0].country"
geojs_io_lookup() {
result=$(timeout 3 curl -4 -s "https://get.geojs.io/v1/ip/country.json?ip=$external_ip" | jq -r ".[0].country" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
geojs_io_lookup_v6() {
result=$(timeout 3 curl -4 -s "https://get.geojs.io/v1/ip/country.json?ip=$external_ipv6" | jq -r ".[0].country" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
iplocation_com_lookup() {
curl -s -X POST "https://iplocation.com" -A "$USER_AGENT" --form "ip=$external_ip" | jq -r ".country_code"
result=$(timeout 3 curl -4 -s -X POST "https://iplocation.com" -A "$USER_AGENT" --form "ip=$external_ip" | jq -r ".country_code" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
iplocation_com_lookup_v6() {
result=$(timeout 3 curl -4 -s -X POST "https://iplocation.com" -A "$USER_AGENT" --form "ip=$external_ipv6" | jq -r ".country_code" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
geoapify_com_lookup() {
# TODO: Add automatic API key parsing
api_key="b8568cb9afc64fad861a69edbddb2658"
curl -s "https://api.geoapify.com/v1/ipinfo?&ip=$external_ip&apiKey=$api_key" | jq -r ".country.iso_code"
result=$(timeout 3 curl -4 -s "https://api.geoapify.com/v1/ipinfo?&ip=$external_ip&apiKey=$api_key" | jq -r ".country.iso_code" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
geoapify_com_lookup_v6() {
# TODO: Add automatic API key parsing
api_key="b8568cb9afc64fad861a69edbddb2658"
result=$(timeout 3 curl -4 -s "https://api.geoapify.com/v1/ipinfo?&ip=$external_ipv6&apiKey=$api_key" | jq -r ".country.iso_code" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ipapi_is_lookup() {
curl -s "https://api.ipapi.is/?q=$external_ip" | jq -r ".location.country_code"
result=$(timeout 3 curl -4 -s "https://api.ipapi.is/?q=$external_ip" | jq -r ".location.country_code" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ipapi_is_lookup_v6() {
result=$(timeout 3 curl -4 -s "https://api.ipapi.is/?q=$external_ipv6" | jq -r ".location.country_code" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
freeipapi_com_lookup() {
curl -s "https://freeipapi.com/api/json/$external_ip" | jq -r ".countryCode"
result=$(timeout 3 curl -4 -s "https://freeipapi.com/api/json/$external_ip" | jq -r ".countryCode" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
freeipapi_com_lookup_v6() {
result=$(timeout 3 curl -4 -s "https://freeipapi.com/api/json/$external_ipv6" | jq -r ".countryCode" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
4_ipwho_de_lookup() {
result=$(timeout 3 curl -4 -s ipwho.de/json | jq -r '.country_code' 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ipbase_com_lookup() {
curl -s "https://api.ipbase.com/v2/info?ip=$external_ip" | jq -r ".data.location.country.alpha2"
result=$(timeout 3 curl -4 -s "https://api.ipbase.com/v2/info?ip=$external_ip" | jq -r ".data.location.country.alpha2" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ipbase_com_lookup_v6() {
result=$(timeout 3 curl -4 -s "https://api.ipbase.com/v2/info?ip=$external_ipv6" | jq -r ".data.location.country.alpha2" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ip_sb_lookup() {
curl -s "https://api.ip.sb/geoip/$external_ip" -A "$USER_AGENT" | jq -r ".country_code"
result=$(timeout 3 curl -4 -s "https://api.ip.sb/geoip/$external_ip" -A "$USER_AGENT" | jq -r ".country_code" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
ip_sb_lookup_v6() {
result=$(timeout 3 curl -4 -s "https://api.ip.sb/geoip/$external_ipv6" -A "$USER_AGENT" | jq -r ".country_code" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
maxmind_com_lookup() {
curl -s "https://geoip.maxmind.com/geoip/v2.1/city/me" -H "Referer: https://www.maxmind.com" | jq -r ".country.iso_code"
result=$(timeout 3 curl -4 -s "https://geoip.maxmind.com/geoip/v2.1/city/me" -H "Referer: https://www.maxmind.com" | jq -r ".country.iso_code" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
maxmind_com_lookup_v6() {
result=$(timeout 3 curl -6 -s "https://geoip.maxmind.com/geoip/v2.1/city/me" -H "Referer: https://www.maxmind.com" | jq -r ".country.iso_code" 2>/dev/null)
if [ $? -eq 124 ]; then
echo ""
elif [ "$result" == "null" ]; then
echo ""
elif [ ${#result} -gt 7 ]; then
echo ""
else
echo "$result"
fi
}
main() {
@ -292,36 +946,59 @@ main() {
declare -a results
get_ipv4
check_service "$RIPE_DOMAIN" ripe_rdap_lookup
check_service "$IPINFO_DOMAIN" ipinfo_io_lookup
check_service "$IPREGISTRY_DOMAIN" ipregistry_co_lookup
check_service "$IPAPI_DOMAIN" ipapi_com_lookup
check_service "$DB_IP_DOMAIN" db_ip_com_lookup
check_service "$IPDATA_DOMAIN" ipdata_co_lookup
check_service "$IPWHOIS_DOMAIN" ipwhois_io_lookup
check_service "$IFCONFIG_DOMAIN" ifconfig_co_lookup
check_service "$WHOER_DOMAIN" whoer_net_lookup
check_service "$IPQUERY_DOMAIN" ipquery_io_lookup
check_service "$COUNTRY_IS_DOMAIN" country_is_lookup
check_service "$CLEANTALK_DOMAIN" cleantalk_org_lookup
check_service "$IP_API_DOMAIN" ip_api_com_lookup
# NOTE: Disabled due to captcha
# check_service "$IPGEOLOCATION_DOMAIN" ipgeolocation_io_lookup
check_service "$IPAPI_CO_DOMAIN" ipapi_co_lookup
# NOTE: Disabled due to captcha
# check_service "$FINDIP_DOMAIN" findip_net_lookup
check_service "$GEOJS_DOMAIN" geojs_io_lookup
check_service "$IPLOCATION_DOMAIN" iplocation_com_lookup
check_service "$GEOAPIFY_DOMAIN" geoapify_com_lookup
check_service "$IPAPI_IS_DOMAIN" ipapi_is_lookup
check_service "$FREEIPAPI_DOMAIN" freeipapi_com_lookup
check_service "$IPBASE_DOMAIN" ipbase_com_lookup
check_service "$IP_SB_DOMAIN" ip_sb_lookup
check_service "$MAXMIND_COM_DOMAIN" maxmind_com_lookup
if IPV6_ADDR=$(ip -6 addr show scope global | awk '/inet6/ {print $2}' | cut -d'/' -f1) && [ -n "$IPV6_ADDR" ]; then
get_ipv6
check_service "$CLOUDFLARE_DOMAIN" cloudflare_lookup cloudflare_lookup_v6
check_service "$COUNTRY_IS_DOMAIN" country_is_lookup country_is_lookup_v6
check_service "$DB_IP_DOMAIN" db_ip_com_lookup db_ip_com_lookup_v6
check_service "$FREEIPAPI_DOMAIN" freeipapi_com_lookup freeipapi_com_lookup_v6
check_service "$GEOAPIFY_DOMAIN" geoapify_com_lookup geoapify_com_lookup_v6
check_service "$GEOJS_DOMAIN" geojs_io_lookup geojs_io_lookup_v6
check_service "$IFCONFIG_DOMAIN" ifconfig_co_lookup ifconfig_co_lookup_v6
check_service "$IPAPI_DOMAIN" ipapi_com_lookup ipapi_com_lookup_v6
check_service "$IPAPI_CO_DOMAIN" ipapi_co_lookup ipapi_co_lookup_v6
check_service "$IPAPI_IS_DOMAIN" ipapi_is_lookup ipapi_is_lookup_v6
check_service "$IPBASE_DOMAIN" ipbase_com_lookup ipbase_com_lookup_v6
check_service "$IPDATA_DOMAIN" ipdata_co_lookup ipdata_co_lookup_v6
check_service "$IPINFO_DOMAIN" ipinfo_io_lookup ipinfo_io_lookup_v6
check_service "$IPLOCATION_DOMAIN" iplocation_com_lookup iplocation_com_lookup_v6
check_service "$IPQUERY_DOMAIN" ipquery_io_lookup ipquery_io_lookup_v6
check_service "$IPREGISTRY_DOMAIN" ipregistry_co_lookup ipregistry_co_lookup_v6
check_service "$IPWHOIS_DOMAIN" ipwhois_io_lookup ipwhois_io_lookup_v6
check_service "$IP_SB_DOMAIN" ip_sb_lookup ip_sb_lookup_v6
check_service "$MAXMIND_COM_DOMAIN" maxmind_com_lookup maxmind_com_lookup_v6
check_service "$RIPE_DOMAIN" ripe_rdap_lookup ripe_rdap_lookup_v6
check_service "$WHOER_DOMAIN" whoer_net_lookup whoer_net_lookup_v6
check_service "$YOUTUBE_DOMAIN" youtube_lookup youtube_lookup_v6
else
check_service "$CLOUDFLARE_DOMAIN" cloudflare_lookup
check_service "$COUNTRY_IS_DOMAIN" country_is_lookup
check_service "$DB_IP_DOMAIN" db_ip_com_lookup
check_service "$FREEIPAPI_DOMAIN" freeipapi_com_lookup
check_service "$GEOAPIFY_DOMAIN" geoapify_com_lookup
check_service "$GEOJS_DOMAIN" geojs_io_lookup
check_service "$IFCONFIG_DOMAIN" ifconfig_co_lookup
check_service "$IPAPI_DOMAIN" ipapi_com_lookup
check_service "$IPAPI_CO_DOMAIN" ipapi_co_lookup
check_service "$IPAPI_IS_DOMAIN" ipapi_is_lookup
check_service "$IPBASE_DOMAIN" ipbase_com_lookup
check_service "$IPDATA_DOMAIN" ipdata_co_lookup
check_service "$IPINFO_DOMAIN" ipinfo_io_lookup
check_service "$IPLOCATION_DOMAIN" iplocation_com_lookup
check_service "$IPQUERY_DOMAIN" ipquery_io_lookup
check_service "$IPREGISTRY_DOMAIN" ipregistry_co_lookup
check_service "$IPWHOIS_DOMAIN" ipwhois_io_lookup
check_service "$IP_SB_DOMAIN" ip_sb_lookup
check_service "$MAXMIND_COM_DOMAIN" maxmind_com_lookup
check_service "$RIPE_DOMAIN" ripe_rdap_lookup
check_service "$WHOER_DOMAIN" whoer_net_lookup
check_service "$YOUTUBE_DOMAIN" youtube_lookup
fi
clear_screen
clear_screen
print_results
}

BIN
test_example.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB