Created
August 29, 2014 16:47
-
-
Save rnagle/f38f62f6750fce7ead89 to your computer and use it in GitHub Desktop.
A command line interface for the services provided by http://ipinfo.io
This file contains hidden or 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 | |
function print_help() { | |
echo "A command line interface for the services provided by http://ipinfo.io | |
Example usage: | |
ipinfo [ADDRESS] [ip | hostname | loc | org | city | region | country | phone | geo] | |
ipinfo 8.8.8.8 geo | |
{ "ip": "8.8.8.8", "city": null, "region": null, "country": "US", "loc": "38.0000,-97.0000" } | |
ipinfo help | |
Prints this help screen | |
" | |
exit 0; | |
} | |
function fetch_url() { | |
base_url="http://ipinfo.io"; | |
url="${base_url}/${1}"; | |
if [[ $2 != '' ]] | |
then | |
url="${url}/${2}"; | |
fi | |
ret=$(curl -s "$url"); | |
echo $ret | |
} | |
if [[ $# < 1 ]] | |
then | |
print_help; | |
fi | |
if [[ $1 == 'help' ]] | |
then | |
print_help; | |
else | |
value=$(fetch_url $@); | |
fi | |
if [[ $value != '' ]] | |
then | |
echo $value; | |
exit 0; | |
else | |
echo "Error: see usage examples by typing 'ipinfo help'"; | |
exit 1; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment