What Is IP Geofencing? How It Works and Where It Fails
IP geofencing applies rules by a visitor's IP location. Lookups from 9 Nov 2026 show a VPN reading as Germany and a relay in the wrong country. Tested code.

On 9 November 2026, GeoIPHub looked up eight addresses and ran each one through a country rule. A Mullvad VPN server and a Tor exit both read as Germany, and the geolocation was not wrong. An Apple Private Relay exit came back as Angola while Apple's own feed says Zambia. A private address came back with its country set to the literal string none.
Each of those results breaks a different kind of naive fence. Below we explain how a fence works, show those lookups, and give a tested Node.js rule that decides allow or deny by country and still does something sensible when the lookup fails.

How IP geofencing works: a boundary, a lookup and an action
IP geofencing works by turning each request's IP address into a location, then applying a rule you wrote in advance. There are three parts, and a fourth that most tutorials skip.
- The boundary: a list of ISO country codes, written as an allowlist or a blocklist.
- The lookup: a geolocation database or API that converts the IP to a country, and optionally a region and city.
- The trust check: whether the IP is a VPN, proxy, Tor, relay or hosting address, which decides if the location means anything.
- The action: allow, block, redirect, localize, or ask for more proof.
Geo-blocking is the deny case of that action, and geo-restriction is the broader word for limiting what a region can see. GeoIPHub returns the location in geo.country_code, geo.region and geo.city, and the trust check in detection.is_vpn, is_proxy, is_tor, is_relay and is_hosting, on the same response.
IP geofencing and GPS geofencing solve different problems
IP geofencing uses the network address on every request, while GPS geofencing uses a device's location with the user's permission. The word "geofencing" covers both, which is why comparisons get confused.
IP geofencing
- Data source: IP address on every request
- Precision: Country strongest, region usable
- User friction: None
- Best for: Licensing, compliance, fraud, localization
- Main weakness: Reads the network exit, not the person
GPS geofencing
- Data source: Device GPS, with permission
- Precision: Street or building level
- User friction: Location prompt and usually an app
- Best for: Proximity marketing, logistics
- Main weakness: Needs an app and consent

For anything that happens in a browser, the IP-based fence is the practical tool because it needs nothing from the user. GPS wins only when you have a native app and truly need building-level position.
IP geofencing is used wherever a rule depends on a jurisdiction
IP geofencing is used wherever the right answer changes at a border: rights, regulation, pricing, risk. The same primitive serves very different stakes.
Content licensing
- What the fence does: Keeps media inside licensed territories
- Typical action: Allow only in licensed countries
Regulated products
- What the fence does: Follows rules that differ by jurisdiction
- Typical action: Deny where the product is prohibited
Sanctions
- What the fence does: Avoids serving embargoed locations
- Typical action: Deny, and log the decision
Pricing and language
- What the fence does: Picks the local currency or store
- Typical action: Localize, never block
Fraud and abuse
- What the fence does: Raises scrutiny on unusual locations
- Typical action: Step-up verification
Ad spend protection
- What the fence does: Keeps campaigns inside target markets
- Typical action: Filter clicks from elsewhere
Sanctions show what skipping a fence can cost. In December 2020 OFAC settled with BitGo for $98,830, saying the company "had reason to know" users were in sanctioned jurisdictions "based on Internet Protocol (IP) address data" that it collected for login security but did not use for compliance. Licensing is the other hard-edged case, and our guide to enforcing regional content licensing with geolocation goes further into it.
Blocking is not always permitted, either. For customers in the EU, Regulation 2018/302 says a trader "shall not, through the use of technological measures or otherwise, block or limit a customer's access" to its online interface for reasons related to nationality, residence or establishment, with an exception where a legal requirement applies. None of this is legal advice, but a fence is a legal decision as well as a technical one.
The country in a lookup describes the exit, not the person
An IP geolocation result says where the network exit is, and that is only sometimes where the person is. Five kinds of address separate the two.
VPN or proxy exit
- What the country means: The exit server's country, chosen by the user
- What the fence should do: Treat the location as unverified
Tor exit
- What the country means: The exit relay's country, unrelated to the user
- What the fence should do: Treat the location as unverified
iCloud Private Relay
- What the country means: The user's real region, by Apple's design
- What the fence should do: Keep the user, take the country from Apple's row
Mobile or CGNAT
- What the country means: The carrier gateway's country
- What the fence should do: Trust country, not city; never block one address
Hosting or cloud
- What the country means: Where the server sits, not a person
- What the fence should do: Treat as a server unless it is a relay

A VPN exit's country is the exit's, whether it is a commercial VPN or a Tor exit. The geolocation is correct about the machine and tells you nothing about the visitor, so the country is not evidence of anything.
Private Relay is the opposite case. Apple's operator guide says the service "preserves the region the user is in, so your server can trust the region assigned to the IP address it sees". Relay users are real customers in the right country, so treat iCloud Private Relay and Cloudflare WARP differently from a VPN.
Mobile and CGNAT addresses need a smaller adjustment. Carriers assign the public address at a gateway, so the country is usually right while the city often is not, and one address can front many subscribers. GeoIPHub flags the addresses it has classified this way with detection.is_mobile and threat.is_cgnat. The exception is roaming: a 2024 study of Airalo eSIMs found that Airalo "often decouples the geographical location of the public internet gateway" from the base operator's country, so a traveller's phone can show a third country. Read a phone's country as a strong hint rather than a fact.
What eight lookups on 9 November 2026 showed
A country-only allowlist of DE, GB, AU and ZM got three of eight addresses wrong on 9 November 2026: it would have admitted the Mullvad server and the Tor exit, and refused anyone Apple's feed places in Zambia on that relay. We looked up seven public infrastructure addresses and one private address, keyless and at least ten seconds apart, between 09:03 and 09:09 UTC. This is a sample chosen to show behaviour, not a benchmark, and the last item in each entry is the rule from the code further down.
185.213.155.73
- What it is: Mullvad server de-fra-wg-001
geo.country_code: DE- Signals: is_vpn, score 100, block
- Strict rule decided: deny (vpn)
185.220.101.1
- What it is: Tor exit, TORSERVERS-NET
geo.country_code: DE- Signals: is_tor, score 100, block
- Strict rule decided: deny (tor)
45.83.220.7
- What it is: Mullvad network, not on Mullvad's list
geo.country_code: SE- Signals: is_vpn, score 46, review
- Strict rule decided: deny (vpn)
104.28.46.99
- What it is: iCloud Private Relay
geo.country_code: AO (Apple says ZM)- Signals: is_relay, score 9, allow
- Strict rule decided: allow, using Apple's country
104.28.28.41
- What it is: iCloud Private Relay
geo.country_code: AU (Apple says AU)- Signals: is_relay, score 9, allow
- Strict rule decided: allow
172.224.226.1
- What it is: iCloud Private Relay on Akamai
geo.country_code: GB (Apple says GB)- Signals: is_relay and is_hosting, score 24, allow
- Strict rule decided: allow
45.33.32.156
- What it is: Cloud server, Nmap's test host
geo.country_code: US- Signals: is_hosting, score 10, allow
- Strict rule decided: deny (hosting)
10.0.0.1
- What it is: Private address, not routable
geo.country_code: none- Signals: is_bogon, score 24, allow
- Strict rule decided: deny (no country)
Here is the trimmed response for the first address, from the lookup at 09:03:47 UTC. A fence keyed on location alone reads Germany and lets it through. The other half of the same response explains why it should not.
{
"ip": "185.213.155.73",
"asn": {
"asn": 39351,
"org": "ESAB-AS - 31173 Services AB",
"asn_type": "hosting",
"connection_type": "datacenter"
},
"geo": {
"country_code": "DE",
"region": "Hesse",
"city": "Frankfurt am Main (Innenstadt I)",
"geo_confidence": 0.8
},
"detection": {
"is_vpn": true,
"is_proxy": false,
"is_tor": false,
"is_relay": false,
"is_hosting": true,
"vpn_provider": "Mullvad"
},
"threat": { "threat_types": ["vpn"], "is_bogon": false },
"scoring": {
"fraud_score": 100,
"recommended_action": "block",
"detection_methods": ["known_vpn_server", "wireguard_open", "datacenter_with_vpn_proxy", "no_ptr_datacenter"]
}
}
Three things in these results changed how we would write a rule.
A relay's country can be wrong in our data, and by a whole country. We first logged this on 12 October 2026 and it had not changed on 9 November. GeoIPHub's location fields come from the DB-IP database, and our relay ingest takes only the address ranges from Apple's feed, so Apple's location does not reach the response. At 09:04:16 UTC we got AO and Luanda for 104.28.46.99. Apple's CSV, fetched at 09:07 UTC the same day, says:
104.28.46.99/32,ZM,,Lusaka,
A plain rule allowing Zambia would refuse a real user on that exit. For relays, take the country from Apple's row. The Python matcher in our iCloud Private Relay detection guide looks it up, and the code below takes the result as its third argument.
geo_confidence does not measure confidence. It read 0.8 on all three relays, including the one in the wrong country. In GeoIPHub's code the value follows how much of the place name was filled in: 0.8 with a city, 0.5 with a region only, 0.2 with a country only. Do not use it as a probability.
A private address returned allow and the country none. The string is truthy and sits on no blocklist, so a blocklist fence waves it through, and recommended_action scores risk, not location, so it says nothing about a missing country. A private address usually means your load balancer's address reached the code instead of the client's, so read the real client IP before you fence on it.
Country rules are the strongest level, but no number settles it
IP geofencing is most reliable at the country level, yet no public figure measures that level for the addresses you will actually see. Vendors publish 99.8% and higher. CAIDA's 2020 RIPE IPmap paper calls such claims "upper bounds", and it cites an independent test on known addresses where NetAcuity and MaxMind GeoLite2 scored between 70.5% and 90.0% at country level. That test covered routers, and the paper notes routers get less attention from commercial data providers than end users do, so read it as a hard case, not a forecast for your traffic.
We have not measured country accuracy for GeoIPHub's own data, so we will not quote a figure for it. The practical guidance holds anyway: rule on country, go to region only with a soft action, and never hard-block on city. Our guide to how accurate IP geolocation is at each level has the city-level studies.
A country rule in Node.js that fails safely
The rule below decides allow or deny by country, refuses to trust the country on a VPN, proxy or Tor exit, and has an explicit answer for lookup failure. It needs Node 18 or later and has no dependencies.
// geofence.mjs (Node 18+, no dependencies). Run it on your server, not in a browser.
const API = "https://api.geoiphub.com/v1/lookup/";
// One lookup. Returns the parsed response, or null on any failure:
// network error, timeout, bad JSON, or a non-200 status such as 429 or 500.
export async function lookup(ip, { apiKey, timeoutMs = 3000, fetchFn = fetch } = {}) {
try {
const res = await fetchFn(API + encodeURIComponent(ip), {
headers: apiKey ? { "x-api-key": apiKey } : {},
signal: AbortSignal.timeout(timeoutMs),
});
if (!res.ok) return null;
return await res.json();
} catch {
return null;
}
}
// data: lookup() result, or null if the lookup failed.
// appleCountry: optional country from Apple's egress CSV for this relay address.
export function decide(data, policy, appleCountry) {
const result = (action, reason, country = null) => ({ action, reason, country });
if (!data?.geo || !data?.detection) return result(policy.onError, "lookup_failed");
const { geo, detection: d, threat } = data;
const inside = (cc) => (policy.allow ? policy.allow.has(cc) : !policy.block.has(cc));
// Empty fields come back as the string "none", which is truthy and in no list.
if (geo.country_code === "none" || threat?.is_bogon) {
return result(policy.onUnknown, "no_country");
}
// A VPN, proxy or Tor exit's country is the exit's, not the person's.
if (d.is_tor || d.is_vpn || d.is_proxy) {
const why = d.is_tor ? "tor" : d.is_vpn ? "vpn" : "proxy";
return result(policy.onAnonymizer, why, geo.country_code);
}
// A relay keeps the user in their region, so its country is usable, but ask
// Apple's row first and never hard-deny on a database value alone.
if (d.is_relay) {
const country = appleCountry ?? geo.country_code;
if (inside(country)) return result("allow", "relay_inside", country);
return result(appleCountry ? "deny" : "step_up", "relay_outside", country);
}
// A hosting address is a server. Check this after the relay branch, because
// some Private Relay exits sit on hosting networks.
if (d.is_hosting) return result(policy.onHosting, "hosting", geo.country_code);
const ok = inside(geo.country_code);
return result(ok ? "allow" : "deny", ok ? "inside" : "outside", geo.country_code);
}
// Licensing or compliance: an unverified location is the exposure, so fail closed.
export const STRICT = {
allow: new Set(["DE", "GB", "AU", "ZM"]),
onError: "deny", onUnknown: "deny", onAnonymizer: "deny", onHosting: "deny",
};
// Localization: a wrong guess costs little, so fail open and keep the page up.
export const SOFT = {
block: new Set(["CU"]),
onError: "allow", onUnknown: "allow", onAnonymizer: "step_up", onHosting: "allow",
};
Use the strict policy where an unverified location is the risk and the soft one where a wrong guess costs little. lookup() returns null on any failure, so decide() has one path for it: a timeout, a 429 and a 500 all reach onError.
We ran this code on Node 24 on 9 November 2026 against the eight saved responses above, four constructed ordinary addresses (we do not look up household IPs), and simulated failures: a network error, a 429, a 500, invalid JSON, an empty body and a 200 ms timeout. All 28 checks passed, including every row in the table above. Two more calls through the real lookup() at 09:11 UTC returned 200 and matched: 104.28.46.99 gave step_up without Apple's row, and 45.33.32.156 gave deny for hosting.
Before shipping, send your x-api-key header. Keyless calls are limited to 30 a minute, the 30th is already a 429, and it locks the address out for two hours, so a busy fence would lock itself out. Cache decisions per IP so one visitor does not spend a lookup per page view, run the rule in server middleware or an edge worker before the page renders, and log reason so you can audit each decision later.
Where a fence still fails, and when not to use one
A fence that checks for anonymizers still misses what no list has seen, so a false flag is not proof of a real location. On 26 October 2026 a Private Internet Access server from that provider's saved server data came back as is_vpn: false in GeoIPHub's API. GeoIPHub's is_proxy flag covers proxies it has observed, including on residential and mobile lines, so an exit it has not seen looks like an ordinary home connection.
Real customers also trip it: travellers, staff on a corporate gateway, and roaming phones. That is why the strict rule should end in a route to appeal and the soft rule should never block.
So the verdict: use IP geofencing for country-level rules where a good answer most of the time is what you need, such as localization, fraud friction and most licensing. Do not use it alone when you must prove where a person physically is, or for anything finer than a region. Layer device location or identity checks on top in those cases.
Start with the address you are least sure about. Paste it into the free IP lookup tool and read geo.country_code next to the detection flags, because the fence is only as honest as the pair.
Frequently Asked Questions
What is IP geofencing?
IP geofencing uses a visitor's IP address to place them in a country or region, then allows, blocks, redirects or localizes the request. GeoIPHub's API returns geo.country_code and the VPN, proxy, Tor and relay flags on one lookup, so the same call gives the location and the reason to doubt it. Unlike GPS geofencing, it needs no device permission.
What is the difference between IP geofencing and geo-blocking?
Geo-blocking is one outcome of geofencing: denying access based on location. Geo-restriction is the wider term for limiting what a region can see, and geofencing is the whole rule, a boundary plus a lookup plus an action, which can also redirect or localize. In GeoIPHub's data the same geo.country_code drives all of those actions.
How accurate is IP geofencing?
Country is the level IP geofencing handles best, region is usable and city is approximate. Vendors claim 99.8% or higher at country level, but CAIDA's 2020 paper treats those as upper bounds and cites a study of router addresses at 70.5% to 90.0%. GeoIPHub takes location from the DB-IP database and has not measured its own country accuracy, so treat any single percentage with care.
Can users bypass IP geofencing with a VPN?
Yes. A VPN, proxy or Tor exit carries the exit's country, so a location-only rule lets it through. On 9 November 2026 GeoIPHub returned DE for both a Mullvad server and a Tor exit, with detection.is_vpn and detection.is_tor set on the same lookup, so a fence can refuse to trust the country. A VPN no list knows about will still pass.
Is IP geofencing legal and GDPR-compliant?
It is widely used, but the answer depends on the purpose. EU Regulation 2018/302 bars a trader from blocking or redirecting a customer's access to its online interface for reasons related to nationality, residence or establishment, unless a legal requirement applies, and sanctions rules can require blocking. An IP address can be personal data under GDPR, so store as little as you can; GeoIPHub's country field lets a fence act on coarse location only. This is not legal advice.
What data do I need to implement IP geofencing?
At minimum, IP-to-country data. A fence that enforces anything also needs VPN, proxy, Tor, relay and hosting flags, because the country alone cannot tell you whether to believe it. GeoIPHub returns all of them on one lookup, including on the free tier of 1,500 lookups a day.
The team behind the GeoIPHub API
Written by the GeoIPHub team, the people who build the GeoIPHub IP intelligence API and its scanner. Drafts are prepared with AI assistance and edited by the team; API examples are real lookups against the live API unless labelled illustrative.


