← Back to Blog
2026-03-023 min readby DevUtilz

IP Lookup and Geolocation Tools

IPNetworkingGeolocationTools

IP Lookup and Geolocation Tools

IP lookup returns information about an IP address including location, ISP, and other metadata.

IP Address Types

IPv4

192.168.1.1
8.8.8.8

IPv6

2001:4860:4860::8888
2607:f8b0:4009::b

Public vs Private IPs

| Range | Type | Example | |-------|------|---------| | 10.0.0.0 - 10.255.255.255 | Private | 10.0.0.1 | | 172.16.0.0 - 172.31.255.255 | Private | 172.16.0.1 | | 192.168.0.0 - 192.168.255.255 | Private | 192.168.1.1 | | Rest | Public | 8.8.8.8 |

IP Lookup Services

Using ip-api.com (free)

// Note: Requires backend proxy to avoid CORS
async function lookupIP(ip) {
  const response = await fetch(`http://ip-api.com/json/${ip}`);
  return response.json();
}

// Example response
{
  status: "success",
  country: "United States",
  countryCode: "US",
  region: "CA",
  regionName: "California",
  city: "Mountain View",
  lat: 37.386,
  lon: -122.084,
  timezone: "America/Los_Angeles",
  isp: "Google LLC",
  org: "Google Public DNS",
  as: "AS15169 Google LLC"
}

Using ipinfo.io

const response = await fetch(`https://ipinfo.io/${ip}/json`);
const data = await response.json();
// { ip, city, region, country, org, ... }

Browser Client Info

// Get user's IP (from server)
app.get('/my-ip', (req, res) => {
  res.json({
    ip: req.ip || req.connection.remoteAddress,
    headers: req.headers['x-forwarded-for']
  });
});

IP Validation

function isValidIPv4(ip) {
  const parts = ip.split('.');
  if (parts.length !== 4) return false;
  return parts.every(part => {
    const num = parseInt(part, 10);
    return num >= 0 && num <= 255 && part === num.toString();
  });
}

function isValidIPv6(ip) {
  // Simplified check
  return /^[0-9a-fA-F:]+$/.test(ip) && ip.includes(':');
}

Common Use Cases

1. Analytics

function getVisitorLocation(req) {
  return {
    ip: req.ip,
    country: req.headers['cf-ipcountry'], // Cloudflare
    city: req.headers['x-vercel-ip-city'] // Vercel
  };
}

2. Content Localization

async function getLocalizedContent(ip) {
  const { country } = await lookupIP(ip);
  
  if (country === 'DE') return germanContent;
  if (country === 'FR') return frenchContent;
  return englishContent;
}

3. Rate Limiting by IP

const rateLimit = new Map();

function checkRateLimit(ip) {
  const now = Date.now();
  const requests = rateLimit.get(ip) || [];
  
  // Remove old requests
  const recent = requests.filter(t => now - t < 60000);
  
  if (recent.length > 100) {
    throw new Error('Rate limit exceeded');
  }
  
  recent.push(now);
  rateLimit.set(ip, recent);
}

Limitations

  • Inaccurate - IP location can be wrong by hundreds of miles
  • VPN/Proxy - Shows VPN location, not real location
  • Mobile - Often shows ISP headquarters
  • Privacy - Can be blocked or spoofed

Free APIs

| Service | Limits | |---------|--------| | ip-api.com | 45 requests/min | | ipinfo.io | 50K requests/month | | ipgeolocation.io | 1500 requests/day | | ipapi.co | 10K requests/month |

Conclusion

Use IP lookup for analytics and basic geolocation. Don't rely on it for security - it's easily spoofed. Combine with other signals for better accuracy.