JavaScript

JavaScript Examples

Works in the browser. Works in Node.js. Works in Deno and Bun too. The Fetch API is everywhere now.

Browser Examples

Get Your Own IP

const response = await fetch("https://whatismyip.technology/api/me");
const data = await response.json();
console.log(`Your IP: ${data.ip}`);

CORS is enabled on all endpoints, so this works from any domain. No proxy needed.

Full IP Lookup

const response = await fetch("https://whatismyip.technology/api/8.8.8.8");
const data = await response.json();
console.log(`City: ${data.city}`);
console.log(`Country: ${data.country}`);
console.log(`ISP: ${data.asn.name}`);

Geolocation Only

const response = await fetch("https://whatismyip.technology/api/8.8.8.8/geo");
const geo = await response.json();
console.log(`${geo.city}, ${geo.region}, ${geo.country}`);

ASN and Network Info

const response = await fetch("https://whatismyip.technology/api/8.8.8.8/asn");
const asn = await response.json();
console.log(`ASN: ${asn.number} (${asn.name})`);

Privacy and Threat Detection

const response = await fetch("https://whatismyip.technology/api/8.8.8.8/privacy");
const privacy = await response.json();
console.log(`VPN: ${privacy.is_vpn}`);
console.log(`Tor: ${privacy.is_tor}`);

Company and Abuse Info

const response = await fetch("https://whatismyip.technology/api/8.8.8.8/company");
const company = await response.json();
console.log(`${company.name} (${company.type})`);

Bulk Lookup

const response = await fetch("https://whatismyip.technology/api/bulk", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ ips: ["8.8.8.8", "1.1.1.1", "208.67.222.222"] })
});
const results = await response.json();
results.forEach(r => console.log(`${r.ip} -> ${r.country}`));

With Error Handling

async function lookupIP(ip) {
  try {
    const url = ip
      ? `https://whatismyip.technology/api/${ip}`
      : "https://whatismyip.technology/api/me";

    const response = await fetch(url);

    if (!response.ok) {
      throw new Error(`HTTP ${response.status}: ${response.statusText}`);
    }

    return await response.json();
  } catch (error) {
    console.error(`Lookup failed: ${error.message}`);
    return null;
  }
}

const data = await lookupIP("8.8.8.8");
if (data) {
  console.log(`${data.ip} is in ${data.city}, ${data.country}`);
}

Node.js Example

Node 18+ has fetch built in. For older versions, install node-fetch.

// Works in Node 18+ without any packages
const API_BASE = "https://whatismyip.technology/api/me";

async function getMyIP() {
  const res = await fetch(API_BASE);
  const data = await res.json();
  return data.ip;
}

async function lookupIP(ip) {
  const res = await fetch(`${API_BASE}/${ip}`);
  return res.json();
}

async function bulkLookup(ips) {
  const res = await fetch(`${API_BASE}/bulk`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ ips })
  });
  return res.json();
}

// Use it
const myIP = await getMyIP();
console.log(`My IP: ${myIP}`);

const info = await lookupIP("8.8.8.8");
console.log(`Google DNS is in ${info.city}, ${info.country}`);

TypeScript Interface

If you’re using TypeScript, here are the response types.

interface IPLookupResponse {
  ip: string;
  city: string;
  region: string;
  country: string;
  country_code: string;
  latitude: number;
  longitude: number;
  postal_code: string;
  timezone: string;
  asn: {
    number: number;
    name: string;
    org: string;
    route: string;
  };
  privacy: {
    is_vpn: boolean;
    is_proxy: boolean;
    is_tor: boolean;
    is_hosting: boolean;
  };
  company: {
    name: string;
    type: string;
    domain: string;
  };
}

interface GeoResponse {
  city: string;
  region: string;
  country: string;
  country_code: string;
  latitude: number;
  longitude: number;
  postal_code: string;
  timezone: string;
}

interface PrivacyResponse {
  is_vpn: boolean;
  is_proxy: boolean;
  is_tor: boolean;
  is_hosting: boolean;
}

async function lookupIP(ip: string): Promise<IPLookupResponse> {
  const res = await fetch(`https://whatismyip.technology/api/${ip}`);
  if (!res.ok) throw new Error(`HTTP ${res.status}`);
  return res.json();
}

These types cover the main shapes. The actual API may include additional fields, so feel free to extend them as needed.