Skip to content

Instantly share code, notes, and snippets.

@YamlEngineer
Created April 20, 2022 09:19
Show Gist options
  • Save YamlEngineer/0aaa2882d6338d45f510c538523b7831 to your computer and use it in GitHub Desktop.
Save YamlEngineer/0aaa2882d6338d45f510c538523b7831 to your computer and use it in GitHub Desktop.
get ip info
#!/bin/bash
if [[ ! -f /tmp/.ipinfolastrequest ]] || [[ $(date +%s) > $(cat /tmp/.ipinfolastrequest) ]]; then
$(curl --silent http://ip-api.com/json -o /tmp/.ip-api.json)
$(echo $(date +%s --date '5 seconds') >| /tmp/.ipinfolastrequest)
fi
if [[ $1 != '--help' ]] && [[ ! -z $1 ]]; then
Result=$(cat /tmp/.ip-api.json | jq -r .$1)
if [[ $Result = "null" ]]; then
echo "command not found" && exit
fi
echo $Result
elif [[ $1 = "--help" ]] || [[ -z $1 ]]; then
echo "Usage: ipinfo [<options>] [<command>]"
echo "
██╗██████╗ ██╗███╗ ██╗███████╗ ██████╗
██║██╔══██╗██║████╗ ██║██╔════╝██╔═══██╗
██║██████╔╝██║██╔██╗ ██║█████╗ ██║ ██║
██║██╔═══╝ ██║██║╚██╗██║██╔══╝ ██║ ██║
██║██║ ██║██║ ╚████║██║ ╚██████╔╝
╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝ ╚═════╝
"
echo "Options:
--help Show this message and exit."
echo "Commands: [country,countryCode,region,regionName,city,zip,lat,lon,timezone,isp,org,as,query]"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment