aboutsummaryrefslogtreecommitdiff
path: root/geoip
diff options
context:
space:
mode:
Diffstat (limited to 'geoip')
-rwxr-xr-xgeoip24
1 files changed, 24 insertions, 0 deletions
diff --git a/geoip b/geoip
new file mode 100755
index 0000000..4b4f521
--- /dev/null
+++ b/geoip
@@ -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,
+ }'