Last active
November 14, 2024 09:13
-
-
Save ArmanTaheriGhaleTaki/d74bae5b8ede71eef8cd3bf9a2c3ae99 to your computer and use it in GitHub Desktop.
using https://check-host.net/check-ping ping API to check if a IP is accessible from Iran
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irping() { | |
ip=$1 | |
nodes=("ir1" "ir3" "ir5" "ir6") | |
for node in "${nodes[@]}"; do | |
# Make the API request and store the response | |
response=$(curl -s -H "Accept: application/json" "https://check-host.net/check-ping?host=${ip}&node=ir1.node.check-host.net&node=ir3.node.check-host.net&node=ir5.node.check-host.net&node=ir6.node.check-host.net") | |
# Check for "limit_exceeded" error in the response | |
error_message=$(echo "$response" | jq -r '.error') | |
if [ "$error_message" == "limit_exceeded" ]; then | |
echo "Rate limit exceeded." | |
return 1 | |
fi | |
# Extract the "ok" value from the response | |
ok_value=$(echo "$response" | jq -r '."ok"') | |
# Correctly form the dynamic jq path | |
tmp=".nodes.\"${node}.node.check-host.net\"[2]" | |
# Use jq to get the city from the response | |
city=$(echo "$response" | jq -r "$tmp") | |
# Print the result | |
echo "${city}: ok = ${ok_value}" | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment