Skip to content

Instantly share code, notes, and snippets.

@miladj3
Forked from ArmanTaheriGhaleTaki/irping.sh
Created November 14, 2024 09:13
Show Gist options
  • Save miladj3/516b91bb83dc17436d438888108047be to your computer and use it in GitHub Desktop.
Save miladj3/516b91bb83dc17436d438888108047be 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
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