diff options
Diffstat (limited to 'geoip')
-rwxr-xr-x | geoip | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -0,0 +1,24 @@ +#!/bin/sh + +# geoip: Locate an IP address in the world. Requires `jq`. + +API="http://ip-api.com/json" + +if [ "$#" -ne 1 ] || echo "$1" | grep -qvxP "(\d{1,3}\.){3}\d{1,3}"; then + echo "please provide a valid IP address" >&2 + exit 1 +fi + +curl -s "$API/$1" | + jq '{ + ip: .query, + isp: .isp, + org: .org, + country: .country, + regionName: .regionName, + city: .city, + zip: .zip, + lat: .lat, + lon: .lon, + timezone: .timezone, + }' |