Skip to content

Instantly share code, notes, and snippets.

@codingoutloud
Created November 21, 2021 01:24
Show Gist options
  • Save codingoutloud/4d3262d3c6b02ece30a27b14c143e807 to your computer and use it in GitHub Desktop.
Save codingoutloud/4d3262d3c6b02ece30a27b14c143e807 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ $# -eq 1 ]; then
IP="$1"
## NEED AN AZURE MAP API KEY
## Create an Azure Map account in the Azure portal to get a new APIKEY.
AZUREMAP_APIKEY='...'
## Azure Map API to look up the COUNTRY (two-char ISO) of the IP
if ! [ -x "$(command -v jq)" ]; then
curl -s "https://atlas.microsoft.com/geolocation/ip/json?subscription-key=rUHIhr3-f6BHEHsM0wjWHlKDH9SvU8bqfnwbJQblsVw&api-version=1.0&ip=$IP"
else
curl -s "https://atlas.microsoft.com/geolocation/ip/json?subscription-key=rUHIhr3-f6BHEHsM0wjWHlKDH9SvU8bqfnwbJQblsVw&api-version=1.0&ip=$IP" | jq -r '.countryRegion.isoCode'
fi
else
echo "usage: . azipcheck.sh <ip address>"
echo "usage: ./azipcheck.sh <ip address>"
echo ""
echo "examples: . azipcheck.sh 94.232.44.12"
echo "examples: ./azipcheck.sh 94.232.44.12"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment