IP lookup template
- Next.js
- React
Find where an IP address is: city, region, timezone and network, for any IP or your visitor’s own.
A Next.js app that looks up where an IP address is. Enter any IPv4 or IPv6 address, or press Use my IP to look up whoever opened the page, and get the city, region, country, postcode, local time, network provider and a map link. Use it as a lookup tool, or lift the API route to localize your own site.

What it does
- Looks up your visitor
- Use my IP reads the visitor’s address from the request, so a deployed copy shows each person where they are.
- City, region and postcode
- Returns the place in full names and codes, with a coordinate, an accuracy radius and a map link.
- Local time and timezone
- Shows the timezone and the current local time there, useful for scheduling and support.
- Network provider
- Names the network behind the IP, such as the ISP or hosting company, with its ASN.
- Keeps your key private
- The browser only talks to your own API route, which validates the IP and limits each visitor to 10 lookups a minute.
How it works
The API route: it picks the IP to look up, checks it, and calls IP Lookup.
export async function GET(request) {
if (!API_KEY) {
return NextResponse.json(
{ error: 'Missing APIVERVE_API_KEY. Add it to .env.local, or to your host’s environment variables, then restart.' },
{ status: 500 }
);
}
const visitor = (request.headers.get('x-forwarded-for') || '').split(',')[0].trim();
if (rateLimited(visitor || 'local')) {
return NextResponse.json({ error: 'Too many requests. Wait a minute and try again.' }, { status: 429 });
}
const asked = (new URL(request.url).searchParams.get('ip') || '').trim().slice(0, 45);
const ip = asked || visitor;
if (!ip || !isIP(ip)) {
return NextResponse.json(
{ error: asked ? 'That isn’t a valid IPv4 or IPv6 address.' : 'Couldn’t detect your IP here. Enter one instead.' },
{ status: 400 }
);
}
if (PRIVATE.test(ip)) {
return NextResponse.json(
{ error: asked ? 'That’s a private network address, so it has no location.' : 'You’re on a local address, which has no location. Deploy the app to look up your real IP, or enter one.' },
{ status: 400 }
);
}
try {
const res = await fetch(`${API_URL}?ip=${encodeURIComponent(ip)}`, {
headers: { 'x-api-key': API_KEY },
cache: 'no-store'
});
const body = await res.json().catch(() => null);
if (!res.ok || body?.status !== 'ok') {
return NextResponse.json({ error: body?.error || `APIVerve returned ${res.status}` }, { status: 502 });
}
return NextResponse.json({ ...body.data, isYou: !asked });
} catch {
return NextResponse.json({ error: 'Couldn’t reach APIVerve. Try again.' }, { status: 502 });
}
}Deploy it
- Get a free API key
The free plan includes 200 credits a month, no card needed. Create your key.
- Deploy it
Click Deploy to Vercel. Vercel copies the repo to your GitHub account and asks for
APIVERVE_API_KEY: paste your key there. - Open your app
Vercel builds it and gives you a live URL, usually in about a minute. Every push to the repo redeploys it.
Try the IP Lookup API — the call this template makes
No key required to try it. Get a key to use it in your app.
{
"status": "ok",
"error": null,
"data": {
"ip": "173.172.81.20",
"country": "US",
"countryName": "United States",
"region": "MO",
"regionName": "Missouri",
"city": "Kansas City",
"continent": "NA",
"continentName": "North America",
"timezone": "America/Chicago",
"coordinates": [
39.0831,
-94.5853
],
"postalCode": "64106",
"accuracyRadius": 20,
"isEU": false,
"asn": "AS11427",
"asnName": "TWC-11427-TEXAS"
}
}