UNPKG

@stacksjs/dnsx

Version:

A command-line & library DNS client. Like dig & dog, but for TypeScript.

86 lines (85 loc) 2.68 kB
import { Buffer } from 'node:buffer'; import https from 'node:https'; import tls from 'node:tls'; /** * Creates a transport instance based on the specified type. * Factory function to get the appropriate transport implementation. * * @param type - The type of transport to create * @returns A transport instance implementing the Transport interface * @throws {Error} If the transport type is not supported * * @example * ```ts * const transport = createTransport(TransportType.UDP) * const response = await transport.query('1.1.1.1', dnsPacket) * ``` */ export declare function createTransport(type: TransportType): Transport; /** * Interface for DNS transport implementations. * All transport types must implement this interface. */ export declare interface Transport { query: (nameserver: string, request: Buffer) => Promise<Buffer> } /** * UDP transport implementation for DNS queries. * Uses UDP datagrams for maximum performance with retransmission support. * * Features: * - Automatic port selection (default: 53) * - Configurable timeout * - Error handling for network issues */ declare class UDPTransport implements Transport { query(nameserver: string, request: Buffer): Promise<Buffer>; } /** * TCP transport implementation for DNS queries. * Used for larger DNS messages and when reliability is crucial. * * Features: * - Length-prefixed messages (RFC 1035) * - Automatic message reassembly * - Connection timeout handling */ declare class TCPTransport implements Transport { query(nameserver: string, request: Buffer): Promise<Buffer>; } /** * TLS transport implementation for DNS queries (DNS-over-TLS). * Provides encrypted DNS communication for enhanced privacy. * * Features: * - TLS 1.2+ encryption * - SNI support * - Certificate validation * - Length-prefixed messages */ declare class TLSTransport implements Transport { query(nameserver: string, request: Buffer): Promise<Buffer>; } /** * HTTPS transport implementation for DNS queries (DNS-over-HTTPS). * Provides encrypted DNS communication over HTTPS for maximum compatibility. * * Features: * - HTTPS POST requests * - Binary DNS wire format * - Standard HTTPS port (443) * - Compatible with HTTP proxies */ declare class HTTPSTransport implements Transport { query(nameserver: string, request: Buffer): Promise<Buffer>; } /** * Available DNS transport protocols. * Each transport type represents a different way to send DNS queries. */ export declare enum TransportType { UDP = 'udp', // Traditional UDP DNS (port 53) TCP = 'tcp', // TCP DNS (port 53) TLS = 'tls', // DNS-over-TLS (port 853) HTTPS = 'https', // DNS-over-HTTPS }