Skip to content

Instantly share code, notes, and snippets.

@rojenzaman
Last active July 11, 2020 13:11
Show Gist options
  • Select an option

  • Save rojenzaman/9197fdf030ee3c5b2238eb9ff999e18b to your computer and use it in GitHub Desktop.

Select an option

Save rojenzaman/9197fdf030ee3c5b2238eb9ff999e18b to your computer and use it in GitHub Desktop.
IP info
#!/bin/bash
function increment_error_code {
error_code=$((error_code + 1))
}
function echo_error {
(>&2 echo -e "${RED}${1}${NC}")
}
function program_exit {
command -v $1 > /dev/null
if [ $? -ne 0 ]; then
echo_error "Please, install \"$1\""
exit $error_code
fi
increment_error_code
}
program_exit jq;
program_exit curl;
curl -s ifconfig.co/json | jq -r "[.ip,.country,.city,.time_zone,.region_name,.asn,.asn_org,.hostname] | @tsv" > .tmp
while IFS=" " read -r ip country city time_zone region_name asn asn_org hostname; do
cat <<EOF
IP : $ip
Country : $country
City : $city
Time Zone : $time_zone
Region Name : $region_name
ASN : $asn
ASN Organization : $asn_org
Hostname : $hostname
EOF
done < .tmp && rm .tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment