HackMyIP
← back to sheets

A curl IP Geolocation One-Liner (No API Key)

~/sheets/curl-ip-geolocation-one-liner.md
1

The Short Answer

2

To geolocate your own IP from the terminal in one line, run curl https://hackmyip.com/api/ip. It returns JSON with your city, region, country, latitude/longitude, ISP, ASN, and a VPN/proxy/datacenter flag — no API key, no signup. To geolocate any IP, run curl 'https://hackmyip.com/api/lookup?ip=8.8.8.8'. Use the web lookup tool if you want a map and a UI.

3

Your Own IP

4
curl https://hackmyip.com/api/ip
5

For a quick human-readable location without the rest of the payload, the bare-root JSON is even smaller:

6
curl hackmyip.com/json
7

Any IP

8
curl 'https://hackmyip.com/api/lookup?ip=1.1.1.1'
9

Note the quotes around the URL — the ? and & in query strings need them in most shells.

10

Parse Just the City and Country

11

With jq installed, you can pull out exactly the fields you want:

12
# City and country for any IP
13
curl -s 'https://hackmyip.com/api/lookup?ip=8.8.8.8' | jq -r '.data.city, .data.country'
14
# Your own ASN
15
curl -s https://hackmyip.com/api/ip | jq -r '.data.asn'
16

Geolocate Many IPs at Once

17

Looping curl over a list works, but the batch endpoint is one round trip for up to 50 addresses:

18
curl -X POST -H "Content-Type: application/json" \
19
-d '{"ips":["8.8.8.8","1.1.1.1","9.9.9.9"]}' https://hackmyip.com/api/bulk
20

For a bigger list and loop guidance, see bulk IP lookup.

21

A Note on Accuracy

22

IP geolocation maps an address to a city and region, not a street. It is an estimate drawn from upstream public databases and can be off, especially for mobile, CGNAT, and VPN/proxy IPs. That last case is exactly why the response also includes a VPN/proxy/datacenter flag: to tell you when the "location" is really a server, not a person. To check whether your own connection looks like a proxy, see the proxy and VPN detector, and to learn how the mapping works, read how IP geolocation works.

23

Frequently Asked Questions

24

How do I geolocate an IP with curl?

25

Run curl 'https://hackmyip.com/api/lookup?ip=8.8.8.8' to geolocate any IP, or curl https://hackmyip.com/api/ip for your own. Both return JSON with city, region, country, ISP, and ASN, with no API key.

26

Can I get IP geolocation without an API key?

27

Yes. HackMyIP's geolocation endpoints are free and need no key or signup. You call the URL directly with curl, fetch, or any HTTP client.

28

How accurate is curl-based IP geolocation?

29

It resolves to a city and region, not a precise address, and is an estimate from public databases. Mobile, CGNAT, and VPN/proxy IPs are the least accurate, which is why the response includes a VPN/proxy/datacenter flag to mark those cases.

30

How do I extract just the city from the response?

31

Pipe the response through jq, for example curl -s 'https://hackmyip.com/api/lookup?ip=8.8.8.8' | jq -r '.data.city'. For the minimal shape, curl hackmyip.com/json returns city and country directly.

32

Can I geolocate many IPs in one call?

33

Yes. POST up to 50 IPs to https://hackmyip.com/api/bulk in a single request. For larger lists, loop the batch endpoint; see the bulk IP lookup page for guidance.

34
Last updated: June 28, 2026