Skip to content

Commit

Permalink
added ipinfo.io support
Browse files Browse the repository at this point in the history
  • Loading branch information
Gurkengewuerz authored and adtac committed Feb 25, 2017
1 parent 953f816 commit 5c21eee
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Command | Description
`climate http-server [port]` | http-server serving the current directory
`climate is-up <domain>` | determine if server is up
`climate httpstat <url>` | visualizes curl statistics with httpstat
`climate ipinfo [ip]` | lookup IP with ipinfo.io API
<br> |
`climate download-file <file>` | download file from server
`climate download-dir <dir>` | download dir from server
Expand Down
32 changes: 32 additions & 0 deletions climate
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,34 @@ ix() {
curl $opts -F f:1='<-' $* ix.io/$id
}

ipinfo() {
external_ip="$1"
result=$(curl --silent https://ipinfo.io/$external_ip)
log "curl --silent https://ipinfo.io/$external_ip"

if [[ $result == "Please provide a valid IP address" || -z $result ]]; then
printf "${RED_BOLD}Please provide a valid IP address!\n"
exit
fi

json_ip=$(echo "$result" | jq -r ".ip")
json_hostname=$(echo "$result" | jq -r ".hostname")
json_city=$(echo "$result" | jq -r ".city")
json_region=$(echo "$result" | jq -r ".region")
json_country=$(echo "$result" | jq -r ".country")
json_loc=$(echo "$result" | jq -r ".loc")
json_org=$(echo "$result" | jq -r ".org")
json_postal=$(echo "$result" | jq -r ".postal")


printf "${GREEN_BOLD}IP-Address: ${YELLOW}${json_ip}\n"
printf "${GREEN_BOLD}Hostname: ${YELLOW}${json_hostname}\n"
printf "${GREEN_BOLD}Network: ${YELLOW}${json_org}\n"
printf "${GREEN_BOLD}City: ${YELLOW}${json_city}, ${json_region}, ${json_country}\n"
printf "${GREEN_BOLD}Postal Code: ${YELLOW}${json_postal}\n"
printf "${GREEN_BOLD}Latitude/Longitude: ${YELLOW}${json_loc}\n"
}

# ----------------------------------------------------------------------------
# Parse Args

Expand Down Expand Up @@ -203,6 +231,7 @@ help=$(
shelp "http-server [port]" "http-server serving the current directory"
shelp "is-up <domain>" "determine if server is up"
shelp "httpstat <url>" "visualizes curl statistics with httpstat"
shelp "ipinfo [ip]" "lookup IP with ipinfo.io API"
printf "\n${PLAIN_BOLD}SSH:\n"
shelp "download-file <file>" "download file from server"
Expand Down Expand Up @@ -573,6 +602,9 @@ elif [[ $command == "is-up" ]]; then
is-up "$commandargs"
fi

elif [[ $command == "ipinfo" ]]; then
ipinfo "$2"

# ----------------------------------------------------------------------------
# SSH

Expand Down
1 change: 1 addition & 0 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ main() {
system_verify "sensors" "lm-sensors" "lm_sensors"
system_verify "sshfs" "sshfs" "fuse-sshfs"
system_verify "gawk" "gawk" "gawk"
system_verify "jq" "jq" "jq"

npm_verify "http-server" "http-server"
npm_verify "is-up" "is-up-cli"
Expand Down

0 comments on commit 5c21eee

Please sign in to comment.