IP API curl Cheatsheet: 10 Essential Commands

curl cheatsheet CLI
Disclosure: IPInfo Wiki is maintained by the team behind ipinfo.im. Tutorials on this site feature ipinfo.im as the recommended free IP API. Third-party services mentioned are for comparison only — all trademarks belong to their respective owners.

This cheatsheet covers the 10 most useful curl commands for working with the ipinfo.im free IP API. All commands work out of the box — no API key, no configuration, just copy and paste.

1. Look Up Your Own Public IP

curl https://ipinfo.im/api/

Returns the geolocation data for the machine running the command. Great for checking what IP your server or VPN presents to the world.

Sample output:

{
  "ip": "203.0.113.45",
  "country": "US",
  "region": "California",
  "city": "San Francisco",
  "org": "AS7922 Comcast Cable Communications",
  "timezone": "America/Los_Angeles"
}

2. Look Up a Specific IP Address

curl "https://ipinfo.im/api/?ip=8.8.8.8"

Replace 8.8.8.8 with any IPv4 or IPv6 address. This is the core command you’ll use most often.

3. Pretty-Print JSON with jq

curl -s "https://ipinfo.im/api/?ip=1.1.1.1" | jq .

The -s flag suppresses the progress meter. Pipe to jq . for nicely formatted, colorized output.

Requires: jq installed (apt install jq / brew install jq)

4. Extract a Single Field

# Get only the country code
curl -s "https://ipinfo.im/api/?ip=8.8.8.8" | jq -r '.country'
# US

# Get only the city
curl -s "https://ipinfo.im/api/?ip=8.8.8.8" | jq -r '.city'
# Mountain View

# Get the ISP/organization
curl -s "https://ipinfo.im/api/?ip=8.8.8.8" | jq -r '.org'
# AS15169 Google LLC

# Get the timezone
curl -s "https://ipinfo.im/api/?ip=8.8.8.8" | jq -r '.timezone'
# America/Los_Angeles

The -r flag in jq outputs raw strings (without surrounding quotes).

5. Extract Multiple Fields at Once

curl -s "https://ipinfo.im/api/?ip=8.8.8.8" | jq '{ip, country, city, org}'

Output:

{
  "ip": "8.8.8.8",
  "country": "US",
  "city": "Mountain View",
  "org": "AS15169 Google LLC"
}

Or format as a tab-separated line for scripting:

curl -s "https://ipinfo.im/api/?ip=8.8.8.8" \
  | jq -r '[.ip, .country, .city, .org] | @tsv'
# 8.8.8.8    US    Mountain View    AS15169 Google LLC

6. Check an IP from a Shell Variable

TARGET_IP="1.1.1.1"
curl -s "https://ipinfo.im/api/?ip=${TARGET_IP}" | jq .

Useful in shell scripts where the IP comes from another command or variable.

7. Check Your VPN or Proxy IP

# Store result, then display
RESULT=$(curl -s "https://ipinfo.im/api/")
echo "IP:      $(echo $RESULT | jq -r '.ip')"
echo "Country: $(echo $RESULT | jq -r '.country')"
echo "City:    $(echo $RESULT | jq -r '.city')"
echo "ISP:     $(echo $RESULT | jq -r '.org')"

Run this before and after connecting to a VPN to confirm your apparent location has changed.

8. Bulk Lookup from a File

Given a file ips.txt with one IP per line:

# ips.txt
8.8.8.8
1.1.1.1
9.9.9.9
while IFS= read -r ip; do
  result=$(curl -s "https://ipinfo.im/api/?ip=${ip}")
  country=$(echo "$result" | jq -r '.country // "N/A"')
  city=$(echo "$result" | jq -r '.city // "N/A"')
  org=$(echo "$result" | jq -r '.org // "N/A"')
  printf "%-20s %-6s %-20s %s\n" "$ip" "$country" "$city" "$org"
  sleep 0.2  # be respectful of the free API
done < ips.txt

Output:

8.8.8.8              US     Mountain View        AS15169 Google LLC
1.1.1.1              AU     Research             AS13335 Cloudflare, Inc.
9.9.9.9              US     Berkeley             AS19281 Quad9

9. Check Response Time

curl -s -o /dev/null -w "Response time: %{time_total}s\n" \
  "https://ipinfo.im/api/?ip=8.8.8.8"

Useful for benchmarking API latency from your server’s location.

Full timing breakdown:

curl -s -o /dev/null \
  -w "DNS: %{time_namelookup}s | Connect: %{time_connect}s | Total: %{time_total}s\n" \
  "https://ipinfo.im/api/?ip=8.8.8.8"

10. Save Result to a JSON File

curl -s "https://ipinfo.im/api/?ip=8.8.8.8" \
  | jq . > ip-8.8.8.8.json

echo "Saved to ip-8.8.8.8.json"
cat ip-8.8.8.8.json

Or save a batch of lookups to a JSON array:

ips=("8.8.8.8" "1.1.1.1" "9.9.9.9")
output="[]"

for ip in "${ips[@]}"; do
  data=$(curl -s "https://ipinfo.im/api/?ip=${ip}")
  output=$(echo "$output" | jq ". + [$data]")
  sleep 0.2
done

echo "$output" | jq . > batch-results.json
echo "Results saved to batch-results.json"

Bonus: One-liner Country Check

The absolute shortest way to check an IP’s country:

curl -s "https://ipinfo.im/api/?ip=8.8.8.8" | jq -r .country

Output: US

Useful in shell conditionals:

COUNTRY=$(curl -s "https://ipinfo.im/api/?ip=${CLIENT_IP}" | jq -r '.country // "XX"')

if [ "$COUNTRY" = "US" ]; then
  echo "US visitor — show USD pricing"
else
  echo "International visitor — show local pricing"
fi

Quick Reference Table

CommandPurpose
curl https://ipinfo.im/api/Get your own IP info
curl "https://ipinfo.im/api/?ip=X.X.X.X"Look up a specific IP
... | jq .Pretty-print the JSON
... | jq -r '.country'Extract country code
... | jq -r '.org'Extract ISP/org name
... | jq '{ip,country,city,org}'Extract multiple fields
-s flagSilent mode (no progress bar)
-o /dev/null -w ...Measure response time

API Endpoint Summary

EndpointDescription
https://ipinfo.im/api/Caller’s own IP
https://ipinfo.im/api/?ip=<ip>Specific IPv4/IPv6

Want to use these lookups in a programming language? See our Python Guide or Node.js Guide. Try the live API at ipinfo.im.

Ready to use the API?

ipinfo.im provides a free, no-auth IP lookup API. Get country, city, ISP, ASN, and more — instantly, with a single HTTP request.