Created
April 20, 2022 09:19
-
-
Save YamlEngineer/0aaa2882d6338d45f510c538523b7831 to your computer and use it in GitHub Desktop.
get ip info
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
#!/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