blob: 4b4f521ad58b762e2cad24b6f7bd72c76dbb0dbf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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,
}'
|