aicrawlers 0.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js ADDED
@@ -0,0 +1,524 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/crawlers.ts
4
+ var GOOGLE_RDNS = ["googlebot.com", "google.com", "googleusercontent.com"];
5
+ var LIST = [
6
+ // OpenAI
7
+ { name: "GPTBot", operator: "OpenAI", purpose: "training", ipRanges: "https://openai.com/gptbot.json" },
8
+ { name: "OAI-SearchBot", operator: "OpenAI", purpose: "search", ipRanges: "https://openai.com/searchbot.json" },
9
+ { name: "ChatGPT-User", operator: "OpenAI", purpose: "user", ipRanges: "https://openai.com/chatgpt-user.json" },
10
+ { name: "ChatGPT Agent", operator: "OpenAI", purpose: "user" },
11
+ { name: "OAI-AdsBot", operator: "OpenAI", purpose: "other" },
12
+ // Anthropic
13
+ { name: "ClaudeBot", operator: "Anthropic", purpose: "training" },
14
+ { name: "Claude-SearchBot", operator: "Anthropic", purpose: "search" },
15
+ { name: "Claude-User", operator: "Anthropic", purpose: "user" },
16
+ { name: "Claude-Web", operator: "Anthropic", purpose: "other" },
17
+ { name: "anthropic-ai", operator: "Anthropic", purpose: "training" },
18
+ { name: "Claude-Code", operator: "Anthropic", purpose: "user" },
19
+ { name: "Claude-Agent", operator: "Anthropic", purpose: "user" },
20
+ // Perplexity
21
+ { name: "PerplexityBot", operator: "Perplexity", purpose: "search", ipRanges: "https://www.perplexity.com/perplexitybot.json" },
22
+ { name: "Perplexity-User", operator: "Perplexity", purpose: "user", ipRanges: "https://www.perplexity.com/perplexity-user.json" },
23
+ // Google
24
+ { name: "Google-Extended", operator: "Google", purpose: "training", robotsOnly: true },
25
+ { name: "Google-CloudVertexBot", operator: "Google", purpose: "other", rdns: GOOGLE_RDNS },
26
+ { name: "GoogleOther", operator: "Google", purpose: "other", rdns: GOOGLE_RDNS },
27
+ { name: "GoogleOther-Image", operator: "Google", purpose: "other", rdns: GOOGLE_RDNS },
28
+ { name: "GoogleOther-Video", operator: "Google", purpose: "other", rdns: GOOGLE_RDNS },
29
+ { name: "Gemini-Deep-Research", operator: "Google", purpose: "user" },
30
+ { name: "Google-NotebookLM", operator: "Google", purpose: "user" },
31
+ { name: "GoogleAgent-Mariner", operator: "Google", purpose: "user" },
32
+ { name: "Google-Agent", operator: "Google", purpose: "user" },
33
+ // Apple
34
+ { name: "Applebot", operator: "Apple", purpose: "search", rdns: ["applebot.apple.com"] },
35
+ { name: "Applebot-Extended", operator: "Apple", purpose: "training", robotsOnly: true },
36
+ // Meta
37
+ { name: "Meta-ExternalAgent", operator: "Meta", purpose: "training" },
38
+ { name: "Meta-ExternalFetcher", operator: "Meta", purpose: "user" },
39
+ { name: "FacebookBot", operator: "Meta", purpose: "training" },
40
+ { name: "meta-webindexer", operator: "Meta", purpose: "search" },
41
+ // Amazon
42
+ { name: "Amazonbot", operator: "Amazon", purpose: "search", rdns: ["crawl.amazonbot.amazon"] },
43
+ { name: "Amzn-SearchBot", operator: "Amazon", purpose: "search" },
44
+ { name: "Amzn-User", operator: "Amazon", purpose: "user" },
45
+ { name: "NovaAct", operator: "Amazon", purpose: "user" },
46
+ { name: "bedrockbot", operator: "Amazon", purpose: "other" },
47
+ // Microsoft
48
+ { name: "AzureAI-SearchBot", operator: "Microsoft", purpose: "search" },
49
+ // Mistral
50
+ { name: "MistralAI-Training", operator: "Mistral", purpose: "training" },
51
+ { name: "MistralAI-Index", operator: "Mistral", purpose: "search" },
52
+ { name: "MistralAI-User", operator: "Mistral", purpose: "user" },
53
+ // xAI
54
+ { name: "xAI-Grok", operator: "xAI", purpose: "training" },
55
+ { name: "GrokBot", operator: "xAI", purpose: "other" },
56
+ // ByteDance
57
+ { name: "Bytespider", operator: "ByteDance", purpose: "training" },
58
+ { name: "TikTokSpider", operator: "ByteDance", purpose: "training" },
59
+ { name: "DoubaoBot", operator: "ByteDance", purpose: "other" },
60
+ // Other AI companies
61
+ { name: "DeepSeekBot", operator: "DeepSeek", purpose: "training" },
62
+ { name: "QwenBot", operator: "Alibaba", purpose: "training" },
63
+ { name: "KimiBot", operator: "Moonshot AI", purpose: "training" },
64
+ { name: "MoonshotBot", operator: "Moonshot AI", purpose: "training" },
65
+ { name: "Kimi-SearchBot", operator: "Moonshot AI", purpose: "search" },
66
+ { name: "Kimi-User", operator: "Moonshot AI", purpose: "user" },
67
+ { name: "TongyiBot", operator: "Alibaba", purpose: "user" },
68
+ { name: "Hunyuan", operator: "Tencent", purpose: "training" },
69
+ { name: "ERNIEBot", operator: "Baidu", purpose: "training" },
70
+ { name: "YiyanBot", operator: "Baidu", purpose: "user" },
71
+ { name: "YiBot", operator: "01.AI", purpose: "training" },
72
+ { name: "CCBot", operator: "Common Crawl", purpose: "training" },
73
+ { name: "DuckAssistBot", operator: "DuckDuckGo", purpose: "search" },
74
+ { name: "cohere-training-data-crawler", operator: "Cohere", purpose: "training" },
75
+ { name: "cohere-ai", operator: "Cohere", purpose: "other" },
76
+ { name: "AI2Bot", operator: "Allen Institute for AI", purpose: "training" },
77
+ { name: "Ai2Bot-Dolma", operator: "Allen Institute for AI", purpose: "training" },
78
+ { name: "PanguBot", operator: "Huawei", purpose: "training" },
79
+ { name: "PetalBot", operator: "Huawei", purpose: "search" },
80
+ { name: "YandexAdditional", operator: "Yandex", purpose: "other", match: ["yandexadditionalbot"] },
81
+ { name: "Bravebot", operator: "Brave", purpose: "search" },
82
+ { name: "kagi-fetcher", operator: "Kagi", purpose: "user" },
83
+ { name: "ExaBot", operator: "Exa", purpose: "search" },
84
+ { name: "TavilyBot", operator: "Tavily", purpose: "search" },
85
+ { name: "LinerBot", operator: "Liner", purpose: "other" },
86
+ { name: "Manus-User", operator: "Manus", purpose: "user" },
87
+ { name: "Diffbot", operator: "Diffbot", purpose: "training" },
88
+ { name: "YouBot", operator: "You.com", purpose: "search" },
89
+ { name: "PhindBot", operator: "Phind", purpose: "search" },
90
+ { name: "iaskspider", operator: "iAsk.ai", purpose: "search" },
91
+ { name: "Timpibot", operator: "Timpi", purpose: "training" },
92
+ { name: "ImagesiftBot", operator: "Hive", purpose: "training" },
93
+ { name: "Kangaroo Bot", operator: "Kangaroo LLM", purpose: "training" },
94
+ { name: "img2dataset", operator: "img2dataset", purpose: "training" },
95
+ { name: "FirecrawlAgent", operator: "Firecrawl", purpose: "other" },
96
+ { name: "Crawl4AI", operator: "Crawl4AI (open source)", purpose: "other" },
97
+ { name: "Brightbot", operator: "Bright Data", purpose: "other" },
98
+ { name: "Cloudflare-AutoRAG", operator: "Cloudflare", purpose: "search" },
99
+ { name: "LAIONDownloader", operator: "LAION", purpose: "training" },
100
+ { name: "SemrushBot-OCOB", operator: "Semrush", purpose: "other" },
101
+ { name: "Cotoyogi", operator: "ROIS (Japan)", purpose: "training" },
102
+ { name: "ICC-Crawler", operator: "NICT (Japan)", purpose: "training" },
103
+ { name: "omgili", operator: "Webz.io", purpose: "training", match: ["omgilibot"] },
104
+ { name: "Webzio-Extended", operator: "Webz.io", purpose: "training", robotsOnly: true }
105
+ ];
106
+ var listUpdated = "2026-12-01";
107
+ var aiCrawlers = Object.freeze(LIST.map((c) => Object.freeze(c)));
108
+ var PURPOSES = ["training", "search", "user", "other"];
109
+ function isPurpose(value) {
110
+ return PURPOSES.includes(value);
111
+ }
112
+
113
+ // src/match.ts
114
+ var version = true ? "1.1.0" : "0.0.0-dev";
115
+ var escapeRegex = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
116
+ var tokensOf = (c) => [c.name.toLowerCase(), ...c.match ?? []];
117
+ var BY_TOKEN = /* @__PURE__ */ new Map();
118
+ for (const c of aiCrawlers) if (!c.robotsOnly) for (const t of tokensOf(c)) BY_TOKEN.set(t, c);
119
+ var ALTERNATION = [...BY_TOKEN.keys()].sort((a, b) => b.length - a.length).map(escapeRegex).join("|");
120
+ var aiCrawlerPattern = new RegExp(`(?<![a-z0-9])(?:${ALTERNATION})(?![a-z0-9])`, "i");
121
+ function purposeFilter(purpose) {
122
+ if (purpose === void 0) return () => true;
123
+ const list2 = typeof purpose === "string" ? [purpose] : purpose;
124
+ for (const p of list2) if (!isPurpose(p)) throw new TypeError(`Unknown purpose "${p}". Use: ${PURPOSES.join(", ")}.`);
125
+ return (c) => list2.includes(c.purpose);
126
+ }
127
+ function getAiCrawler(userAgent, options = {}) {
128
+ if (!userAgent) return void 0;
129
+ const found = aiCrawlerPattern.exec(userAgent);
130
+ const crawler = found ? BY_TOKEN.get(found[0].toLowerCase()) : void 0;
131
+ if (!crawler || !purposeFilter(options.purpose)(crawler)) return void 0;
132
+ if (options.allow?.some((n) => n.toLowerCase() === crawler.name.toLowerCase())) return void 0;
133
+ return crawler;
134
+ }
135
+
136
+ // src/rules.ts
137
+ function blockedCrawlers(options = {}) {
138
+ const block = options.block ?? ["training"];
139
+ const inPurpose = block === "all" ? () => true : purposeFilter(block);
140
+ const allow = new Set((options.allow ?? []).map((n) => n.toLowerCase()));
141
+ return aiCrawlers.filter((c) => inPurpose(c) && !allow.has(c.name.toLowerCase()));
142
+ }
143
+ function header(options, comment = "#") {
144
+ const block = options.block ?? ["training"];
145
+ const what = block === "all" ? "all AI crawlers" : block.length ? block.join(", ") : "nothing";
146
+ const allowed = options.allow?.length ? ` \xB7 Allowed anyway: ${options.allow.join(", ")}` : "";
147
+ return `${comment} AI crawler rules, generated by aicrawlers ${version}
148
+ ${comment} Blocked: ${what}${allowed}
149
+ `;
150
+ }
151
+ function blockedTokens(options) {
152
+ return blockedCrawlers(options).filter((c) => !c.robotsOnly).flatMap(tokensOf).sort((a, b) => b.length - a.length);
153
+ }
154
+ function portableRegex(tokens, space) {
155
+ return `(^|[^a-z0-9])(${tokens.map((t) => escapeRegex(t).replace(/ /g, space)).join("|")})([^a-z0-9]|$)`;
156
+ }
157
+ function robotsTxt(options = {}) {
158
+ const crawlers = blockedCrawlers(options);
159
+ if (!crawlers.length) return header(options);
160
+ return `${header(options)}${crawlers.map((c) => `User-agent: ${c.name}`).join("\n")}
161
+ Disallow: /
162
+ `;
163
+ }
164
+ function nginxMap(options = {}) {
165
+ const tokens = blockedTokens(options).map((t) => escapeRegex(t).replace(/ /g, "\\s"));
166
+ const rule = tokens.length ? ` "~*(?<![a-z0-9])(?:${tokens.join("|")})(?![a-z0-9])" 1;
167
+ ` : "";
168
+ return `${header(options)}map $http_user_agent $ai_crawler {
169
+ default 0;
170
+ ${rule}}
171
+ `;
172
+ }
173
+ function apacheRules(options = {}) {
174
+ const tokens = blockedTokens(options);
175
+ if (!tokens.length) return header(options);
176
+ return `${header(options)}<IfModule mod_rewrite.c>
177
+ RewriteEngine On
178
+ RewriteCond %{HTTP_USER_AGENT} ${portableRegex(tokens, "\\s")} [NC]
179
+ RewriteRule ^ - [F,L]
180
+ </IfModule>
181
+ `;
182
+ }
183
+ function caddyRules(options = {}) {
184
+ const tokens = blockedTokens(options);
185
+ if (!tokens.length) return header(options);
186
+ return `${header(options)}@aicrawlers header_regexp User-Agent "(?i)${portableRegex(tokens, " ")}"
187
+ respond @aicrawlers 403
188
+ `;
189
+ }
190
+ var CLOUDFLARE_MAX = 4096;
191
+ var cloudflareChecks = (options) => blockedTokens(options).map((t) => `(lower(http.user_agent) contains "${t.replace(/["\\]/g, "\\$&")}")`);
192
+ function cloudflareExpressions(options = {}) {
193
+ const out = [];
194
+ let current = "";
195
+ for (const check of cloudflareChecks(options)) {
196
+ const next = current ? `${current} or ${check}` : check;
197
+ if (next.length > CLOUDFLARE_MAX && current) {
198
+ out.push(current);
199
+ current = check;
200
+ } else current = next;
201
+ }
202
+ if (current) out.push(current);
203
+ return out;
204
+ }
205
+ function nextProxy(options = {}) {
206
+ const block = options.block ?? ["training"];
207
+ const opts = [];
208
+ if (block !== "all") opts.push(`purpose: ${JSON.stringify(block)}`);
209
+ if (options.allow?.length) opts.push(`allow: ${JSON.stringify(options.allow)}`);
210
+ const args = opts.length ? `, { ${opts.join(", ")} }` : "";
211
+ return `${header(options, "//")}// Save as proxy.ts in your project root (Next.js 16+). For Next.js 15 and earlier, save it
212
+ // as middleware.ts and rename the function to middleware. Run: npm install aicrawlers
213
+ import { NextResponse, type NextRequest } from "next/server";
214
+ import { isAiCrawler } from "aicrawlers";
215
+
216
+ export function proxy(request: NextRequest) {
217
+ if (isAiCrawler(request.headers.get("user-agent")${args})) {
218
+ return new NextResponse("Forbidden", { status: 403 });
219
+ }
220
+ return NextResponse.next();
221
+ }
222
+ `;
223
+ }
224
+
225
+ // src/cidr.ts
226
+ function parseV4(ip) {
227
+ const parts = ip.split(".");
228
+ if (parts.length !== 4) return null;
229
+ let value = 0n;
230
+ for (const part of parts) {
231
+ if (!/^\d{1,3}$/.test(part) || Number(part) > 255) return null;
232
+ value = value << 8n | BigInt(Number(part));
233
+ }
234
+ return value;
235
+ }
236
+ function parseV6(raw) {
237
+ let ip = raw.toLowerCase().replace(/%.*$/, "");
238
+ const v4 = /(\d+\.\d+\.\d+\.\d+)$/.exec(ip);
239
+ if (v4) {
240
+ const n = parseV4(v4[1]);
241
+ if (n === null) return null;
242
+ ip = `${ip.slice(0, v4.index)}${(n >> 16n).toString(16)}:${(n & 0xffffn).toString(16)}`;
243
+ }
244
+ const halves = ip.split("::");
245
+ if (halves.length > 2) return null;
246
+ const head = halves[0] ? halves[0].split(":") : [];
247
+ const tail = halves.length === 2 && halves[1] ? halves[1].split(":") : [];
248
+ const fill = 8 - head.length - tail.length;
249
+ if (halves.length === 1 ? fill !== 0 : fill < 1) return null;
250
+ const groups = [...head, ...Array(halves.length === 2 ? fill : 0).fill("0"), ...tail];
251
+ let value = 0n;
252
+ for (const g of groups) {
253
+ if (!/^[0-9a-f]{1,4}$/.test(g)) return null;
254
+ value = value << 16n | BigInt(parseInt(g, 16));
255
+ }
256
+ return value;
257
+ }
258
+ function parseIp(ip) {
259
+ const trimmed = ip.trim().replace(/^\[|\]$/g, "");
260
+ const v4 = parseV4(trimmed);
261
+ if (v4 !== null) return { v6: false, value: v4 };
262
+ const v6 = trimmed.includes(":") ? parseV6(trimmed) : null;
263
+ if (v6 === null) return null;
264
+ if (v6 >> 32n === 0xffffn) return { v6: false, value: v6 & 0xffffffffn };
265
+ return { v6: true, value: v6 };
266
+ }
267
+ function parseCidr(cidr) {
268
+ const [addr = "", bitsText] = cidr.trim().split("/");
269
+ const ip = parseIp(addr);
270
+ if (!ip) return null;
271
+ const max = ip.v6 ? 128 : 32;
272
+ const bits = bitsText === void 0 ? max : Number(bitsText);
273
+ if (!Number.isInteger(bits) || bits < 0 || bits > max) return null;
274
+ const shift = BigInt(max - bits);
275
+ return { v6: ip.v6, base: ip.value >> shift << shift, bits };
276
+ }
277
+ function inRanges(ip, ranges) {
278
+ const parsed = parseIp(ip);
279
+ if (!parsed) return false;
280
+ return ranges.some((r) => {
281
+ if (r.v6 !== parsed.v6) return false;
282
+ const shift = BigInt((r.v6 ? 128 : 32) - r.bits);
283
+ return parsed.value >> shift << shift === r.base;
284
+ });
285
+ }
286
+
287
+ // src/verify.ts
288
+ var DAY = 864e5;
289
+ var rangeCache = /* @__PURE__ */ new Map();
290
+ function cidrsFromJson(data) {
291
+ const out = [];
292
+ const walk = (v) => {
293
+ if (typeof v === "string") {
294
+ if (v.includes("/")) {
295
+ const c = parseCidr(v);
296
+ if (c) out.push(c);
297
+ }
298
+ } else if (Array.isArray(v)) v.forEach(walk);
299
+ else if (v && typeof v === "object") Object.values(v).forEach(walk);
300
+ };
301
+ walk(data);
302
+ return out;
303
+ }
304
+ async function download(url, options) {
305
+ try {
306
+ const res = await (options.fetch ?? fetch)(url, { signal: AbortSignal.timeout(options.timeout ?? 1e4) });
307
+ if (!res.ok) return void 0;
308
+ const ranges = cidrsFromJson(JSON.parse(await res.text()));
309
+ return ranges.length ? ranges : void 0;
310
+ } catch {
311
+ return void 0;
312
+ }
313
+ }
314
+ function loadRanges(url, options) {
315
+ const ttl = options.cacheTtl ?? DAY;
316
+ const hit = rangeCache.get(url);
317
+ if (hit && Date.now() - hit.at < ttl) return hit.ranges;
318
+ const ranges = download(url, options).then((r) => {
319
+ if (!r) rangeCache.delete(url);
320
+ return r;
321
+ });
322
+ rangeCache.set(url, { at: Date.now(), ranges });
323
+ return ranges;
324
+ }
325
+ async function nodeResolver() {
326
+ try {
327
+ const dns = await import("node:dns/promises");
328
+ return {
329
+ reverse: (ip) => dns.reverse(ip),
330
+ lookup: async (host) => (await dns.lookup(host, { all: true })).map((r) => r.address)
331
+ };
332
+ } catch {
333
+ return void 0;
334
+ }
335
+ }
336
+ function withTimeout(promise, ms) {
337
+ return new Promise((resolve, reject) => {
338
+ const timer = setTimeout(() => reject(Object.assign(new Error("timeout"), { code: "ETIMEOUT" })), ms);
339
+ promise.then(
340
+ (v) => (clearTimeout(timer), resolve(v)),
341
+ (e) => (clearTimeout(timer), reject(e))
342
+ );
343
+ });
344
+ }
345
+ var same = (a, b) => {
346
+ const x = parseIp(a);
347
+ const y = parseIp(b);
348
+ return x !== null && y !== null && x.v6 === y.v6 && x.value === y.value;
349
+ };
350
+ async function checkDns(ip, suffixes, options) {
351
+ const resolver = options.resolver ?? await nodeResolver();
352
+ if (!resolver) return { verified: null, reason: "no DNS resolver here: pass options.resolver" };
353
+ const ms = options.timeout ?? 1e4;
354
+ let hosts;
355
+ try {
356
+ hosts = await withTimeout(resolver.reverse(ip), ms);
357
+ } catch (error) {
358
+ const code = error.code;
359
+ return code === "ENOTFOUND" || code === "ENODATA" ? { verified: false, reason: `${ip} has no reverse DNS name` } : { verified: null, reason: `reverse DNS lookup failed (${code ?? "error"})` };
360
+ }
361
+ const host = hosts.map((h) => h.toLowerCase().replace(/\.$/, "")).find((h) => suffixes.some((s) => h === s || h.endsWith(`.${s}`)));
362
+ if (!host) return { verified: false, reason: `${ip} resolves to ${hosts[0] ?? "nothing"}, not ${suffixes.join(" or ")}` };
363
+ try {
364
+ const addresses = await withTimeout(resolver.lookup(host), ms);
365
+ return addresses.some((a) => same(a, ip)) ? { verified: true, reason: `${ip} is ${host}, which resolves back to it` } : { verified: false, reason: `${host} doesn't resolve back to ${ip}` };
366
+ } catch (error) {
367
+ return { verified: null, reason: `forward DNS lookup failed (${error.code ?? "error"})` };
368
+ }
369
+ }
370
+ async function verifyAiCrawler(request, options = {}) {
371
+ const crawler = getAiCrawler(request.userAgent);
372
+ if (!crawler) return { crawler, verified: null, method: null, reason: "not an AI crawler" };
373
+ const ip = request.ip.trim().replace(/^\[|\]$/g, "");
374
+ if (!parseIp(ip)) return { crawler, verified: null, method: null, reason: `"${request.ip}" is not an IP address` };
375
+ if (crawler.ipRanges) {
376
+ const ranges = await loadRanges(crawler.ipRanges, options);
377
+ if (!ranges) return { crawler, verified: null, method: "ip-ranges", reason: `couldn't download ${crawler.ipRanges}` };
378
+ const ok = inRanges(ip, ranges);
379
+ return {
380
+ crawler,
381
+ verified: ok,
382
+ method: "ip-ranges",
383
+ reason: ok ? `${ip} is in ${crawler.operator}'s published ranges for ${crawler.name}` : `${ip} is not in ${crawler.operator}'s published ranges for ${crawler.name}`
384
+ };
385
+ }
386
+ if (crawler.rdns?.length) {
387
+ const result = await checkDns(ip, crawler.rdns, options);
388
+ return { crawler, method: "rdns", ...result };
389
+ }
390
+ return { crawler, verified: null, method: null, reason: `${crawler.operator} doesn't publish a way to verify ${crawler.name}` };
391
+ }
392
+
393
+ // src/cli.ts
394
+ var GENERATORS = {
395
+ robots: robotsTxt,
396
+ nginx: nginxMap,
397
+ apache: apacheRules,
398
+ caddy: caddyRules,
399
+ cloudflare: (options) => {
400
+ const rules = cloudflareExpressions(options);
401
+ if (rules.length <= 1) return `${rules[0] ?? ""}
402
+ `;
403
+ return rules.map((r, i) => `# Rule ${i + 1} of ${rules.length}: create a custom rule with this expression and the Block action
404
+ ${r}
405
+ `).join("\n");
406
+ },
407
+ next: nextProxy
408
+ };
409
+ var HELP = `aicrawlers ${version}: known AI crawlers, and rules to block them
410
+ ${aiCrawlers.length} crawlers, list updated ${listUpdated}
411
+
412
+ Usage
413
+ aicrawlers check "<user agent>" Is it an AI crawler? (exit code 0 yes, 1 no)
414
+ aicrawlers verify <ip> "<user agent>" Is it really that crawler? (0 real, 1 fake, 3 can't tell)
415
+ aicrawlers list [--json] Every known AI crawler
416
+
417
+ Blocking rules (take the rule options below)
418
+ aicrawlers robots robots.txt
419
+ aicrawlers nginx nginx map
420
+ aicrawlers apache Apache / .htaccess (mod_rewrite)
421
+ aicrawlers caddy Caddyfile
422
+ aicrawlers cloudflare Cloudflare WAF custom rule expression
423
+ aicrawlers next Next.js proxy.ts / middleware.ts
424
+
425
+ Rule options
426
+ --block <purposes> training, search, user, other, or all (default: training)
427
+ --allow <names> Crawlers to leave out, e.g. OAI-SearchBot,PerplexityBot
428
+
429
+ Options
430
+ --purpose <purposes> list/check: only these purposes
431
+ --json Output JSON
432
+ -h, --help Show this help
433
+ -v, --version Show the version
434
+
435
+ Examples
436
+ npx aicrawlers robots --block training >> robots.txt
437
+ npx aicrawlers nginx --block all --allow OAI-SearchBot,PerplexityBot
438
+ npx aicrawlers check "Mozilla/5.0 (compatible; GPTBot/1.2; +https://openai.com/gptbot)"
439
+ npx aicrawlers verify 20.15.240.64 "GPTBot/1.2"
440
+ `;
441
+ function fail(message) {
442
+ process.stderr.write(`aicrawlers: ${message}
443
+ Run "aicrawlers --help" for usage.
444
+ `);
445
+ process.exit(2);
446
+ }
447
+ function parseArgs(argv) {
448
+ const positional2 = [];
449
+ const flags2 = {};
450
+ for (let i = 0; i < argv.length; i++) {
451
+ const arg = argv[i];
452
+ if (arg === "-h") flags2.help = true;
453
+ else if (arg === "-v") flags2.version = true;
454
+ else if (arg.startsWith("--")) {
455
+ const [key, inline] = arg.slice(2).split("=", 2);
456
+ if (key === "json" || key === "help" || key === "version") flags2[key] = true;
457
+ else if (inline !== void 0) flags2[key] = inline;
458
+ else if (i + 1 < argv.length) flags2[key] = argv[++i];
459
+ else fail(`--${key} needs a value`);
460
+ } else positional2.push(arg);
461
+ }
462
+ return { positional: positional2, flags: flags2 };
463
+ }
464
+ var list = (value) => typeof value === "string" ? value.split(",").map((s) => s.trim()).filter(Boolean) : void 0;
465
+ function purposeList(value) {
466
+ const items = list(value);
467
+ if (!items) return void 0;
468
+ for (const p of items) if (!PURPOSES.includes(p)) fail(`unknown purpose "${p}". Use: ${PURPOSES.join(", ")}`);
469
+ return items;
470
+ }
471
+ function ruleOptions(flags2) {
472
+ const block = flags2.block === "all" ? "all" : purposeList(flags2.block);
473
+ return { block, allow: list(flags2.allow) };
474
+ }
475
+ var { positional, flags } = parseArgs(process.argv.slice(2));
476
+ var [command, ...rest] = positional;
477
+ if (flags.version) {
478
+ process.stdout.write(`${version}
479
+ `);
480
+ } else if (flags.help || !command) {
481
+ process.stdout.write(HELP);
482
+ } else if (command === "check") {
483
+ const ua = rest.join(" ");
484
+ if (!ua) fail("check needs a user agent");
485
+ const crawler = getAiCrawler(ua, { purpose: purposeList(flags.purpose) });
486
+ if (flags.json) process.stdout.write(`${JSON.stringify(crawler ?? null, null, 2)}
487
+ `);
488
+ else process.stdout.write(crawler ? `AI crawler: ${crawler.name} (${crawler.operator}, ${crawler.purpose})
489
+ ` : "Not a known AI crawler\n");
490
+ process.exitCode = crawler ? 0 : 1;
491
+ } else if (command === "list") {
492
+ const only = purposeList(flags.purpose);
493
+ const rows = aiCrawlers.filter((c) => !only || only.includes(c.purpose));
494
+ if (flags.json) process.stdout.write(`${JSON.stringify(rows, null, 2)}
495
+ `);
496
+ else {
497
+ const w = Math.max(...rows.map((c) => c.name.length));
498
+ const o = Math.max(...rows.map((c) => c.operator.length));
499
+ for (const c of rows) {
500
+ const note = c.robotsOnly ? " (robots.txt only)" : "";
501
+ process.stdout.write(`${c.name.padEnd(w)} ${c.operator.padEnd(o)} ${c.purpose}${note}
502
+ `);
503
+ }
504
+ }
505
+ } else if (command === "verify") {
506
+ const [ip, ...ua] = rest;
507
+ if (!ip || !ua.length) fail("verify needs an IP and a user agent");
508
+ void verifyAiCrawler({ ip, userAgent: ua.join(" ") }).then((v) => {
509
+ if (flags.json) process.stdout.write(`${JSON.stringify(v, null, 2)}
510
+ `);
511
+ else {
512
+ const verdict = v.verified === true ? "Real" : v.verified === false ? "FAKE" : "Can't tell";
513
+ process.stdout.write(`${verdict}${v.crawler ? ` ${v.crawler.name}` : ""}: ${v.reason}
514
+ `);
515
+ }
516
+ process.exitCode = v.verified === true ? 0 : v.verified === false ? 1 : 3;
517
+ });
518
+ } else if (GENERATORS[command]) {
519
+ const options = ruleOptions(flags);
520
+ const out = GENERATORS[command](options);
521
+ process.stdout.write(out);
522
+ } else {
523
+ fail(`unknown command "${command}"`);
524
+ }
@@ -0,0 +1,30 @@
1
+ type Purpose = "training" | "search" | "user" | "other";
2
+ interface AiCrawler {
3
+ /** Product token: what the crawler sends in its User-Agent and obeys in robots.txt. */
4
+ name: string;
5
+ /** Company or project that runs it. */
6
+ operator: string;
7
+ /**
8
+ * What it collects pages for, from the operator's documentation:
9
+ * - "training": data to train AI models
10
+ * - "search": an AI search or answer product
11
+ * - "user": fetches a page because a person asked an assistant about it
12
+ * - "other": anything else, or not documented
13
+ */
14
+ purpose: Purpose;
15
+ /** Extra lowercase strings matched in the User-Agent. The name always matches. */
16
+ match?: string[];
17
+ /** Only used in robots.txt: it never appears in a User-Agent. */
18
+ robotsOnly?: boolean;
19
+ /** URL of the operator's official JSON list of IP ranges, to tell real requests from fakes. */
20
+ ipRanges?: string;
21
+ /** Reverse-DNS hostname suffixes of real requests, confirmed with a forward lookup. */
22
+ rdns?: string[];
23
+ }
24
+ /** The date the list was last reviewed against operators' documentation and the ai.robots.txt list. */
25
+ declare const listUpdated = "2026-12-01";
26
+ /** Known AI crawlers and fetchers. Frozen: copy it before changing anything. */
27
+ declare const aiCrawlers: readonly Readonly<AiCrawler>[];
28
+ declare const PURPOSES: readonly Purpose[];
29
+
30
+ export { type AiCrawler as A, type Purpose as P, aiCrawlers as a, PURPOSES as b, listUpdated as l };
@@ -0,0 +1,30 @@
1
+ type Purpose = "training" | "search" | "user" | "other";
2
+ interface AiCrawler {
3
+ /** Product token: what the crawler sends in its User-Agent and obeys in robots.txt. */
4
+ name: string;
5
+ /** Company or project that runs it. */
6
+ operator: string;
7
+ /**
8
+ * What it collects pages for, from the operator's documentation:
9
+ * - "training": data to train AI models
10
+ * - "search": an AI search or answer product
11
+ * - "user": fetches a page because a person asked an assistant about it
12
+ * - "other": anything else, or not documented
13
+ */
14
+ purpose: Purpose;
15
+ /** Extra lowercase strings matched in the User-Agent. The name always matches. */
16
+ match?: string[];
17
+ /** Only used in robots.txt: it never appears in a User-Agent. */
18
+ robotsOnly?: boolean;
19
+ /** URL of the operator's official JSON list of IP ranges, to tell real requests from fakes. */
20
+ ipRanges?: string;
21
+ /** Reverse-DNS hostname suffixes of real requests, confirmed with a forward lookup. */
22
+ rdns?: string[];
23
+ }
24
+ /** The date the list was last reviewed against operators' documentation and the ai.robots.txt list. */
25
+ declare const listUpdated = "2026-12-01";
26
+ /** Known AI crawlers and fetchers. Frozen: copy it before changing anything. */
27
+ declare const aiCrawlers: readonly Readonly<AiCrawler>[];
28
+ declare const PURPOSES: readonly Purpose[];
29
+
30
+ export { type AiCrawler as A, type Purpose as P, aiCrawlers as a, PURPOSES as b, listUpdated as l };