generated from Dicken/dickendock
Commit 5: Scanner-Engine (DNS, Portscan, Titel/Favicon, Softwareerkennung, FritzBox TR-064)
This commit is contained in:
25
apps/backend/src/scanner/dns.ts
Normal file
25
apps/backend/src/scanner/dns.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { lookup } from "node:dns/promises";
|
||||
|
||||
export interface DnsResolution {
|
||||
hostname: string;
|
||||
ip: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Versucht der Spezifikation folgend: hostname, hostname.home, hostname.local.
|
||||
* Gibt die erste erfolgreich aufgelöste Variante zurück, sonst null.
|
||||
*/
|
||||
export async function resolveHostname(shortName: string): Promise<DnsResolution | null> {
|
||||
const candidates = [shortName, `${shortName}.home`, `${shortName}.local`];
|
||||
|
||||
for (const hostname of candidates) {
|
||||
try {
|
||||
const { address } = await lookup(hostname);
|
||||
return { hostname, ip: address };
|
||||
} catch {
|
||||
// nächste Variante versuchen
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user