惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
宝玉的分享
宝玉的分享
Jina AI
Jina AI
IT之家
IT之家
博客园 - Franky
MyScale Blog
MyScale Blog
Y
Y Combinator Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
I
InfoQ
雷峰网
雷峰网
WordPress大学
WordPress大学
Microsoft Security Blog
Microsoft Security Blog
Google DeepMind News
Google DeepMind News
美团技术团队
S
SegmentFault 最新的问题
罗磊的独立博客
博客园 - 聂微东
大猫的无限游戏
大猫的无限游戏
H
Help Net Security
D
Docker
博客园 - 司徒正美
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
阮一峰的网络日志
阮一峰的网络日志
M
MIT News - Artificial intelligence

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
IP Geolocation for Fraud Detection — A Developer's Guide
ApogeoAPI · 2026-05-05 · via DEV Community

ApogeoAPI

IP geolocation is one of the most accessible fraud signals available. It won't stop sophisticated attackers, but it catches a significant amount of low-effort fraud with very little implementation overhead.

How IP Geolocation Helps Detect Fraud

  • Impossible travel: A user logs in from Germany, then from Brazil 10 minutes later.
  • Country mismatch: Billing address is in the US, but the IP is in a different region.
  • High-risk region matching: Signups from regions associated with specific fraud patterns.
  • VPN/proxy detection: Hiding location is sometimes a fraud signal (requires specialized APIs).

Signal 1: Impossible Travel

function haversineDistance(lat1: number, lon1: number, lat2: number, lon2: number): number {
const R = 6371; // Earth radius in km
const dLat = (lat2 - lat1) * Math.PI / 180;
const dLon = (lon2 - lon1) * Math.PI / 180;
const a = Math.sin(dLat/2) ** 2 +
Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) * Math.sin(dLon/2) ** 2;
return R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
}
async function checkImpossibleTravel(userId: string, currentIp: string) {
const current = await geolocate(currentIp);
const lastLogin = await db.getLastLogin(userId);
if (!lastLogin) return false;
const distanceKm = haversineDistance(
lastLogin.latitude, lastLogin.longitude,
current.latitude, current.longitude
);
const hoursSince = (Date.now() - lastLogin.timestamp) / 3600000;
const maxPossibleSpeed = 900; // km/h (commercial flight speed)
return distanceKm / hoursSince > maxPossibleSpeed;
}

Enter fullscreen mode Exit fullscreen mode

Signal 2: Country Mismatch

async function checkCountryMismatch(billingCountry: string, ip: string): Promise {
const geo = await geolocate(ip);
return geo.country_code !== billingCountry;
}

Enter fullscreen mode Exit fullscreen mode

Signal 3: High-Risk Regions

const HIGH_RISK_COUNTRIES = new Set(['XX', 'YY']); // Your own list based on data
async function isHighRiskRegion(ip: string): Promise {
const geo = await geolocate(ip);
return HIGH_RISK_COUNTRIES.has(geo.country_code);
}

Enter fullscreen mode Exit fullscreen mode

Signal 4: Anonymous IP / VPN

Standard IP geolocation APIs (including ApogeoAPI) don't detect VPNs or proxies — that requires a dedicated proxy detection database. Services like IPQualityScore or Fraudlabs Pro specialize in this. Use them as an additional layer, not a replacement.

Putting It Together: Risk Score

interface RiskResult {
score: number; // 0–100
reasons: string[];
}
async function calculateRiskScore(
userId: string,
ip: string,
billingCountry: string
): Promise {
const reasons: string[] = [];
let score = 0;
const [impossible, mismatch, highRisk] = await Promise.all([
checkImpossibleTravel(userId, ip),
checkCountryMismatch(billingCountry, ip),
isHighRiskRegion(ip),
]);
if (impossible) { score += 40; reasons.push('Impossible travel detected'); }
if (mismatch)   { score += 30; reasons.push('IP country does not match billing country'); }
if (highRisk)   { score += 20; reasons.push('IP originates from high-risk region'); }
return { score, reasons };
}

Enter fullscreen mode Exit fullscreen mode

Important Caveats

  • Never block solely on IP. VPNs, corporate proxies, and shared IPs create false positives that block legitimate users.
  • Use as one signal among many. Combine with device fingerprinting, behavioral analysis, and payment signals.
  • Consider privacy regulations. Storing IP-derived location data may fall under GDPR or CCPA. Consult your legal team.
  • Communicate clearly. If you flag a user, give them a way to verify identity rather than a silent block.

Originally published at https://apogeoapi.com/blog/ip-geolocation-fraud-detection. Try ApogeoAPI free at apogeoapi.com.