From 5892efdf6b026332ec2d55f1b109287190f8ba2e Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Tue, 7 Oct 2025 07:06:21 +0100 Subject: [PATCH] Implements IP blacklist checking tool --- src/lib/constants/icon-map.ts | 30 + src/lib/constants/nav.ts | 20 + .../api/internal/diagnostics/dnsbl/+server.ts | 304 +++++++ .../dns/blacklist-checker/+page.svelte | 819 ++++++++++++++++++ 4 files changed, 1173 insertions(+) create mode 100644 src/routes/api/internal/diagnostics/dnsbl/+server.ts create mode 100644 src/routes/diagnostics/dns/blacklist-checker/+page.svelte diff --git a/src/lib/constants/icon-map.ts b/src/lib/constants/icon-map.ts index 4da32f9..0b161ac 100644 --- a/src/lib/constants/icon-map.ts +++ b/src/lib/constants/icon-map.ts @@ -253,4 +253,34 @@ export const iconMap: Record = { 'dnssec-chain': ``, signature: ``, // '': ``, + + +// pie-chart +// help-circle +// balance-scale +// code +// test +// performance +// security +// globe-2 +// users +// list-ordered +// tunnel +// user +// flag +// book-open +// shuffle +// template +// share +// list-checks +// clipboard-list +// edit-3 +// mail-check +// eye +// star +// wifi +// play-circle +// formula +// default + }; diff --git a/src/lib/constants/nav.ts b/src/lib/constants/nav.ts index 2fc64e7..5064d03 100644 --- a/src/lib/constants/nav.ts +++ b/src/lib/constants/nav.ts @@ -1168,6 +1168,26 @@ export const SUB_NAV: Record = { 'authenticated', ], }, + { + href: makePath('/diagnostics/dns/blacklist-checker'), + label: 'DNS Blacklist Checker', + description: 'Check if IP or domain is listed on spam blacklists for email deliverability troubleshooting', + icon: 'blacklist', + keywords: [ + 'dnsbl', + 'rbl', + 'blacklist', + 'spam', + 'spamhaus', + 'sorbs', + 'email', + 'deliverability', + 'reputation', + 'blocklist', + 'listing', + 'delisting', + ], + }, { href: makePath('/diagnostics/dns/soa-serial'), label: 'SOA Serial Analyzer', diff --git a/src/routes/api/internal/diagnostics/dnsbl/+server.ts b/src/routes/api/internal/diagnostics/dnsbl/+server.ts new file mode 100644 index 0000000..71f2ece --- /dev/null +++ b/src/routes/api/internal/diagnostics/dnsbl/+server.ts @@ -0,0 +1,304 @@ +import { json, error } from '@sveltejs/kit'; +import type { RequestHandler } from './$types'; +import { promises as dns } from 'node:dns'; + +interface DNSBLRequest { + target: string; // IP or domain +} + +interface RBLResult { + rbl: string; + listed: boolean; + response?: string; + reason?: string; + responseTime: number; + error?: string; + url?: string; + description?: string; +} + +interface DNSBLResponse { + target: string; + targetType: 'ipv4' | 'ipv6' | 'domain'; + resolvedIPs?: string[]; + results: RBLResult[]; + summary: { + totalChecked: number; + listedCount: number; + cleanCount: number; + errorCount: number; + }; + timestamp: string; +} + +// Comprehensive list of major RBLs +const RBLS = [ + // Spamhaus + // { zone: 'zen.spamhaus.org', name: 'Spamhaus ZEN', description: 'Combined blocklist', url: 'https://www.spamhaus.org/lookup/' }, + // { zone: 'sbl.spamhaus.org', name: 'Spamhaus SBL', description: 'Spam sources', url: 'https://www.spamhaus.org/lookup/' }, + // { zone: 'xbl.spamhaus.org', name: 'Spamhaus XBL', description: 'Exploits', url: 'https://www.spamhaus.org/lookup/' }, + // { zone: 'pbl.spamhaus.org', name: 'Spamhaus PBL', description: 'Policy blocklist', url: 'https://www.spamhaus.org/lookup/' }, + { zone: 'dbl.spamhaus.org', name: 'Spamhaus DBL', description: 'Domain blocklist', url: 'https://www.spamhaus.org/lookup/' }, + + // SORBS + { zone: 'dnsbl.sorbs.net', name: 'SORBS', description: 'Spam sources', url: 'https://www.sorbs.net/lookup.shtml' }, + + // SpamCop + { zone: 'bl.spamcop.net', name: 'SpamCop', description: 'Spam reports', url: 'https://www.spamcop.net/bl.shtml' }, + + // Barracuda + { zone: 'b.barracudacentral.org', name: 'Barracuda', description: 'Reputation system', url: 'https://barracudacentral.org/lookups' }, + + // UCEPROTECT + { zone: 'dnsbl-1.uceprotect.net', name: 'UCEPROTECT L1', description: 'Single IPs', url: 'https://www.uceprotect.net/en/rblcheck.php' }, + { zone: 'dnsbl-2.uceprotect.net', name: 'UCEPROTECT L2', description: 'ISP ranges', url: 'https://www.uceprotect.net/en/rblcheck.php' }, + { zone: 'dnsbl-3.uceprotect.net', name: 'UCEPROTECT L3', description: 'Countries/ASNs', url: 'https://www.uceprotect.net/en/rblcheck.php' }, + + // PSBL + { zone: 'psbl.surriel.com', name: 'PSBL', description: 'Passive spam block', url: 'https://psbl.org/' }, + + // Others + // { zone: 'cbl.abuseat.org', name: 'CBL', description: 'Composite blocking', url: 'https://www.abuseat.org/lookup.cgi' }, + { zone: 'dnsbl.dronebl.org', name: 'DroneBL', description: 'Drones/zombies', url: 'https://dronebl.org/lookup' }, + { zone: 'spam.dnsbl.sorbs.net', name: 'SORBS Spam', description: 'Verified spam', url: 'https://www.sorbs.net/lookup.shtml' }, + { zone: 'dul.dnsbl.sorbs.net', name: 'SORBS DUL', description: 'Dynamic IPs', url: 'https://www.sorbs.net/lookup.shtml' }, + + { zone: 'bl.blocklist.de', name: 'Blocklist.de', description: 'Blocklist.de (abusive mail servers)', url: 'https://www.blocklist.de/en/index.html' }, + { zone: 'bl.mailspike.net', name: 'Mailspike', description: 'Mailspike abuse list', url: 'https://mailspike.org/' }, + { zone: 'all.spamrats.com', name: 'SpamRats', description: 'SpamRats RBL', url: 'https://www.spamrats.com/' }, + { zone: 'multi.surbl.org', name: 'SURBL Multi', description: 'URI/domain lists (phishing/malware/abuse)', url: 'https://www.surbl.org/' }, + { zone: 'dnsrbl.org', name: 'DNSRBL', description: 'DNS Real-time Blackhole List', url: 'https://dnsrbl.org/' }, +]; + +function isIPv4(str: string): boolean { + return /^(\d{1,3}\.){3}\d{1,3}$/.test(str); +} + +function isIPv6(str: string): boolean { + return /^([0-9a-fA-F]{0,4}:){2,7}[0-9a-fA-F]{0,4}$/.test(str); +} + +function reverseIPv4(ip: string): string { + return ip.split('.').reverse().join('.'); +} + +function reverseIPv6(ip: string): string { + // Expand IPv6 to full form + const parts = ip.split(':'); + const fullParts: string[] = []; + + for (let i = 0; i < parts.length; i++) { + if (parts[i] === '') { + const zerosNeeded = 8 - parts.filter(p => p !== '').length; + for (let j = 0; j <= zerosNeeded; j++) { + fullParts.push('0000'); + } + } else { + fullParts.push(parts[i].padStart(4, '0')); + } + } + + // Convert to nibble format and reverse + const nibbles = fullParts.slice(0, 8).join('').split('').reverse().join('.'); + return nibbles; +} + +async function checkRBL(ip: string, rbl: typeof RBLS[0], isDomain: boolean): Promise { + const startTime = Date.now(); + + try { + let query: string; + + if (isDomain) { + // For domain blacklists, query domain directly + query = `${ip}.${rbl.zone}`; + } else if (isIPv4(ip)) { + query = `${reverseIPv4(ip)}.${rbl.zone}`; + } else if (isIPv6(ip)) { + query = `${reverseIPv6(ip)}.${rbl.zone}`; + } else { + throw new Error('Invalid IP format'); + } + + const addresses = await dns.resolve4(query); + const responseTime = Date.now() - startTime; + + // Get TXT record for listing reason + let reason: string | undefined; + try { + const txtRecords = await dns.resolveTxt(query); + reason = txtRecords.flat().join(' '); + } catch { + // TXT record optional + } + + // Check if this is an error response rather than actual listing + // Many RBLs return specific codes for errors (e.g., 127.255.255.x for errors) + const response = addresses[0]; + const isErrorResponse = + response.startsWith('127.255.') || // Common error code range + (reason && ( + reason.toLowerCase().includes('open resolver') || + reason.toLowerCase().includes('query refused') || + reason.toLowerCase().includes('not supported') || + reason.toLowerCase().includes('check.spamhaus.org') || + reason.toLowerCase().includes('blocked - see') || + reason.toLowerCase().includes('access denied') || + reason.toLowerCase().includes('please use') + )); + + if (isErrorResponse) { + return { + rbl: rbl.name, + listed: false, + responseTime, + error: reason || 'RBL query blocked or unsupported', + }; + } + + return { + rbl: rbl.name, + listed: true, + response, + reason, + responseTime, + url: rbl.url, + description: rbl.description, + }; + } catch (err: any) { + const responseTime = Date.now() - startTime; + + if (err.code === 'ENOTFOUND' || err.code === 'ENODATA') { + // Not listed + return { + rbl: rbl.name, + listed: false, + responseTime, + }; + } + + // Actual error + return { + rbl: rbl.name, + listed: false, + responseTime, + error: err.message, + }; + } +} + +async function resolveTarget(target: string): Promise<{ type: 'ipv4' | 'ipv6' | 'domain'; ips?: string[] }> { + if (isIPv4(target)) { + return { type: 'ipv4' }; + } + + if (isIPv6(target)) { + return { type: 'ipv6' }; + } + + // It's a domain, resolve to IPs + try { + const ips: string[] = []; + let lastError: Error | null = null; + + try { + const ipv4s = await dns.resolve4(target); + ips.push(...ipv4s); + } catch (err) { + lastError = err as Error; + // No IPv4 + } + + try { + const ipv6s = await dns.resolve6(target); + ips.push(...ipv6s); + } catch (err) { + if (!lastError) lastError = err as Error; + // No IPv6 + } + + if (ips.length === 0) { + // Provide helpful error message based on DNS error + if (lastError && 'code' in lastError) { + if (lastError.code === 'ENOTFOUND') { + throw new Error(`Domain "${target}" does not exist or could not be found`); + } else if (lastError.code === 'ENODATA') { + throw new Error(`Domain "${target}" exists but has no A or AAAA records`); + } else if (lastError.code === 'ETIMEOUT') { + throw new Error(`DNS lookup timed out for "${target}"`); + } + } + throw new Error(`Could not resolve domain "${target}" to any IP addresses`); + } + + return { type: 'domain', ips }; + } catch (err) { + throw new Error(`Failed to resolve domain: ${err instanceof Error ? err.message : 'Unknown error'}`); + } +} + +export const POST: RequestHandler = async ({ request }) => { + try { + const body: DNSBLRequest = await request.json(); + const { target } = body; + + if (!target || typeof target !== 'string' || !target.trim()) { + throw error(400, 'Target IP or domain is required'); + } + + const trimmedTarget = target.trim().toLowerCase(); + + // Resolve target + const { type, ips } = await resolveTarget(trimmedTarget); + + let allResults: RBLResult[] = []; + + if (type === 'domain') { + // Check domain blacklists (DBL) + const domainRBLs = RBLS.filter(rbl => rbl.zone.includes('dbl')); + const domainChecks = domainRBLs.map(rbl => checkRBL(trimmedTarget, rbl, true)); + const domainResults = await Promise.all(domainChecks); + allResults.push(...domainResults); + + // Check IPs against IP blacklists + if (ips && ips.length > 0) { + const ipRBLs = RBLS.filter(rbl => !rbl.zone.includes('dbl')); + + for (const ip of ips) { + const ipChecks = ipRBLs.map(rbl => checkRBL(ip, rbl, false)); + const ipResults = await Promise.all(ipChecks); + allResults.push(...ipResults.map(r => ({ ...r, rbl: `${r.rbl} (${ip})` }))); + } + } + } else { + // Check IP against all IP blacklists + const ipRBLs = RBLS.filter(rbl => !rbl.zone.includes('dbl')); + const checks = ipRBLs.map(rbl => checkRBL(trimmedTarget, rbl, false)); + allResults = await Promise.all(checks); + } + + const summary = { + totalChecked: allResults.length, + listedCount: allResults.filter(r => r.listed).length, + cleanCount: allResults.filter(r => !r.listed && !r.error).length, + errorCount: allResults.filter(r => r.error).length, + }; + + const response: DNSBLResponse = { + target: trimmedTarget, + targetType: type, + resolvedIPs: ips, + results: allResults, + summary, + timestamp: new Date().toISOString(), + }; + + return json(response); + } catch (err) { + console.error('DNSBL check error:', err); + if (err && typeof err === 'object' && 'status' in err) { + throw err; + } + throw error(500, `DNSBL check failed: ${err instanceof Error ? err.message : 'Unknown error'}`); + } +}; diff --git a/src/routes/diagnostics/dns/blacklist-checker/+page.svelte b/src/routes/diagnostics/dns/blacklist-checker/+page.svelte new file mode 100644 index 0000000..ed9994f --- /dev/null +++ b/src/routes/diagnostics/dns/blacklist-checker/+page.svelte @@ -0,0 +1,819 @@ + + + + DNS Blacklist Checker | IP Calc + + + + +
+
+

DNS Blacklist Checker

+

Check if your IP or domain is listed on major spam blacklists (RBLs)

+
+ + +
+
+ + +

Quick Examples

+
+
+ {#each examples as example, i (i)} + + {/each} +
+
+
+ + +
+
{ e.preventDefault(); checkBlacklist(); }}> +
+ + +
+ +
+
+ + + {#if error} +
+ +
+

Error

+

{error}

+
+
+ {/if} + + {#if loading} +
+
+
+ +
+

Checking Blacklists

+

Querying DNS blacklist records for {target}...

+
+
+
+
+ {/if} + + + {#if results} +
+
+

Blacklist Check Results

+
+ + +
0}> +
+ +
+

{results.summary.listedCount === 0 ? 'Clean' : 'Listed on Blacklists'}

+

Target: {results.target} ({results.targetType})

+ {#if results.resolvedIPs && results.resolvedIPs.length > 0} +

Resolved IPs: {results.resolvedIPs.join(', ')}

+ {/if} +
+
+ +
+
+ Total Checked + {results.summary.totalChecked} +
+
+ Clean + {results.summary.cleanCount} +
+
+ Listed + {results.summary.listedCount} +
+
+ Errors + {results.summary.errorCount} +
+
+
+ + + {#if results.results.filter((r: any) => r.listed).length > 0} +
+
+

+ + Listed on Blacklists ({results.results.filter((r: any) => r.listed).length}) +

+
+
+ {#each results.results.filter((r: any) => r.listed) as result (result.rbl)} + + {/each} +
+
+ {/if} + + + {#if results.results.filter((r: any) => !r.listed && !r.error).length > 0} +
+
+ + + + +

+ + Clean Results ({results.results.filter((r: any) => !r.listed && !r.error).length}) +

+
+
+ {#each results.results.filter((r: any) => !r.listed && !r.error) as result (result.rbl)} +
+
+ {result.rbl} + {result.responseTime}ms + + + Clean + +
+
+ {/each} +
+
+
+ {/if} + + + {#if results.results.filter((r: any) => r.error).length > 0} +
+
+ + + + +

+ + Query Warnings ({results.results.filter((r: any) => r.error).length}) +

+
+
+ {#each results.results.filter((r: any) => r.error) as result (result.rbl)} +
+
+ {result.rbl} + + + Warning + +
+
+ Note: + {result.error} +
+
+ {/each} +
+
+

+ + These RBLs could not be queried, possibly due to rate limiting, public resolver restrictions, or API access requirements. + This does not indicate a listing. +

+
+
+
+ {/if} + + +
+
+ + + + +

What do these results mean?

+
+
+
+
Understanding Blacklists
+

+ DNS Blacklists (DNSBLs or RBLs) are databases used to identify IP addresses or domains known for sending spam, + hosting malware, or engaging in malicious activities. Email servers check these lists to filter unwanted mail. +

+
+
+
If You're Listed
+
    +
  • Check the blacklist's website for delisting procedures
  • +
  • Investigate the cause (compromised system, open relay, etc.)
  • +
  • Fix the underlying issue before requesting removal
  • +
  • Most lists automatically delist after a period without incidents
  • +
+
+
+
Major Blacklists Checked
+

+ This tool checks against major RBLs including Spamhaus (ZEN, SBL, XBL, PBL, DBL), SORBS, SpamCop, Barracuda, + UCEPROTECT, PSBL, CBL, and DroneBL. These are commonly used by email servers worldwide. +

+
+
+
+
+
+ {/if} +
+ +