// Fragt je IP-Netz den eingetragenen Inhaber per RDAP ab (öffentliche Registerdaten der Internet-Registries). // Registereinträge können Namen von Privatpersonen enthalten. Diese Rohdatei wird deshalb direkt danach // von 11-netzliste.mjs bereinigt und nie veröffentlicht. // Ergebnis: daten/rdap.jsonl (fortsetzbar) import { appendFileSync, existsSync, readFileSync } from 'node:fs'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; const hier = dirname(fileURLToPath(import.meta.url)); const pfad = (d) => join(hier, 'daten', d); const ziel = pfad('rdap.jsonl'); const ips = readFileSync(pfad('ips-rdap.txt'), 'utf8').split('\n').map((s) => s.trim()).filter(Boolean); const fertig = new Set(existsSync(ziel) ? readFileSync(ziel, 'utf8').trim().split('\n').filter(Boolean).map((z) => JSON.parse(z).ip) : []); const offen = ips.filter((i) => !fertig.has(i)); console.log(`RDAP: ${ips.length} Netze, offen ${offen.length}`); const warte = (ms) => new Promise((r) => setTimeout(r, ms)); setTimeout(() => process.exit(3), 40 * 60 * 1000).unref(); function organisation(eintrag) { const namen = []; const lauf = (liste) => { for (const e of liste ?? []) { const karte = e.vcardArray?.[1] ?? []; const art = karte.find((f) => f[0] === 'kind')?.[3]; const fn = karte.find((f) => f[0] === 'fn')?.[3]; if (art === 'org' && fn && (e.roles ?? []).some((r) => ['registrant', 'administrative'].includes(r))) namen.push({ name: String(fn).slice(0, 100), rolle: e.roles.includes('registrant') ? 'registrant' : 'administrative', handle: e.handle ?? null }); lauf(e.entities); } }; lauf(eintrag.entities); return namen.sort((a, b) => (a.rolle === 'registrant' ? -1 : 1) - (b.rolle === 'registrant' ? -1 : 1))[0] ?? null; } async function frage(ip) { for (let v = 0; v < 4; v++) { try { const r = await fetch(`https://rdap.db.ripe.net/ip/${ip}`, { headers: { Accept: 'application/rdap+json', 'User-Agent': 'municipal-hosting-study/1.0' }, redirect: 'follow', signal: AbortSignal.timeout(15000) }); if (r.status === 429) { await warte(4000 * (v + 1)); continue; } if (!r.ok) return { ip, fehler: `HTTP ${r.status}` }; const j = await r.json(); const org = organisation(j); return { ip, netz: j.name ?? null, land: j.country ?? null, start: j.startAddress ?? null, ende: j.endAddress ?? null, org: org?.name ?? null, orgRolle: org?.rolle ?? null, orgHandle: org?.handle ?? null, zeit: new Date().toISOString() }; } catch (e) { if (v === 3) return { ip, fehler: String(e.message ?? e) }; await warte(1500); } } return { ip, fehler: 'HTTP 429' }; } let pos = 0; await Promise.all(Array.from({ length: 3 }, async () => { while (pos < offen.length) { const ip = offen[pos++]; appendFileSync(ziel, `${JSON.stringify(await frage(ip))}\n`); await warte(250); } })); const alle = readFileSync(ziel, 'utf8').trim().split('\n').map((z) => JSON.parse(z)); console.log(JSON.stringify({ gesamt: alle.length, fehler: alle.filter((z) => z.fehler).length, mitOrg: alle.filter((z) => z.org).length, mitLand: alle.filter((z) => z.land).length })); process.exit(0);