Library to verify Search Engine Bots (Google, Bing, Facebook...) via IP Range and DNS
npm install bot-verifier-idaUser-Agent is not enough. Anyone can fake a User-Agent string to look like Googlebot.
.googlebot.com).
bash
npm install bot-verifier-ida
or
yarn add bot-verifier-ida
🛠️ Usage1. Basic Usage (Check IP Range only)Simple IP verification using internal IP Range lists.TypeScriptimport { BotVerifier } from 'bot-verifier-ida';
const verifier = new BotVerifier();
async function check() {
const ip = '66.249.66.1'; // Real Googlebot IP
const botName = 'googleBot';
const result = await verifier.verifyBot(ip, botName);
if (result.isVerified) {
console.log(✅ Verified! Method: ${result.method});
} else {
console.log(🚫 Fake Bot! Reason: ${result.details});
}
}
check();
2. Advanced Usage (With GeoIP/ASN)If you have a GeoIP service (like MaxMind or ipinfo.io) in your project, pass the ASN data to increase accuracy.TypeScriptconst geoData = {
asn: 15169, // ASN from your GeoIP lookup
org: 'Google LLC' // Org name from your GeoIP lookup
};
const result = await verifier.verifyBot('66.249.66.1', 'googleBot', geoData);
🤖 Supported BotsCurrently supports verification for major bots including:CategoryBotsSearch EnginesgoogleBot, bingBot, duckDuckBot, yandexBot, baiduspider, yeti (Naver), petalBot, appleBotSocial MediafacebookBot, twitterBot, linkedinBot, pinterestBotSEO ToolsahrefsBot, semrushBot, dotBot (Moz), screamingFrogBotAI & CrawlersgptBot (OpenAI), claudeBot, perplexityBot, ccBot (Common Crawl), byteSpider (TikTok)Monitoring & CDNbetterUptimeBot, bunnyCDN📚 API ReferenceverifyBot(ip, botName, geoData?)Returns a Promise.Parameters:ip (string): The IP address of the request.botName (BotName): The standardized key of the bot (e.g., 'googleBot', 'bingBot').geoData (Optional): Object containing { asn: number, org: string }.Return Type (VerificationResult):TypeScript{
isVerified: boolean; // true if legit, false if fake
method: string; // 'ip-range', 'asn', 'reverse-dns', 'failed', or 'error'
details?: string; // Description of result or error message
hostname?: string; // Hostname (if reverse-dns was used)
}
💻 Integration ExamplesNestJS IntegrationUse this library inside a NestJS Service or Middleware to protect your API.TypeScriptimport { Injectable, Logger } from '@nestjs/common';
import { BotVerifier } from 'bot-verifier-ida';
@Injectable()
export class BotVerificationService {
private readonly logger = new Logger(BotVerificationService.name);
private readonly verifier = new BotVerifier();
async verify(ip: string, botName: string) {
const result = await this.verifier.verifyBot(ip, botName);
if (result.isVerified) {
this.logger.log( Verified ${botName} from ${ip});
return true;
}
this.logger.warn(Fake bot detected! IP: ${ip}, Claimed: ${botName});
return false;
}
}
📝 LicenseThis project is licensed under the MIT License.
``