UNPKG

xep-whois

Version:
157 lines (156 loc) 5.68 kB
export type LoggerInterface = { info(...data: any[]): void; debug(...data: any[]): void; error(...data: any[]): void; }; /** * Type of the proxy. Either SOCKS4 or SOCKS5 * @enum */ export declare enum ProxyType { /** * SOCKS4 type of proxy */ SOCKS4 = 0, /** * SOCKS5 type of proxy */ SOCKS5 = 1 } /** * Proxy related data * @interface * */ export interface ProxyData { /** * Proxy IP */ ip: string; /** * Proxy port */ port: number; /** * Username to connect to the proxy */ username?: string | null; /** * Password to connect to the proxy */ password?: string | null; /** * {@link ProxyType} */ type: ProxyType; } /** * WhoIs options * @interface */ export interface WhoIsOptions { /** * TLD of the domain. If the {@link tld} is not provided (or null), then it will be automatically determined as to the given domain name */ tld?: string | null; /** * The encoding type used for WhoIs server and response. By default UTF-8 is used. */ encoding?: string | null; /**{@link ProxyData} */ proxy?: ProxyData | null; /** * The WhoIs server to collect data from. If not provided, the server will automatically determined using the {@link tld} */ server?: string | null; /** * The port of the WhoIs server. By default, port 43 is used. */ serverPort?: number | null; /** * Which data needs to be extracted/parsed from the WhoIs response. * An object can be passed which contains keys of the fields of the WhoIs response. * A copy of the provided object will be returned with the values filled for the provided keys. * * The keys can have default value of empty string. However, if the WhoIs response has multiple values for the same field (eg: 'Domain Status'), * then all the values can be collected by providing a default value of an Array([]). * * Following example shows an object used to collect 'Domain Name', 'Domain Status' (multiple values) and 'Registrar' from WhoIs response * * @example {'Domain Name': '', 'Domain Status': [], 'Registrar': ''} */ parseData?: Object | null; } /** * Response returned from whois function. Contains the raw text from WhoIs server and parsed/formatted WhoIs data (if parsed is true) * * @interface */ export interface WhoIsResponse { /** * Raw text response from WhoIs server */ _raw: string; /** * Parsed/Formatted key-value pairs of the response (if parsed is true) */ parsedData: any | null; } /** * Parse collected raw WhoIs data * * @class */ export declare class WhoIsParser { /** * Iterated through the complete text and returns extracted values * * @param rawData raw text from WhoIs server * @param outputData Data which needs to be extracted from the raw text (key/value pairs). Keys are used to extract from raw text and values are filled. * @returns Filled {@link outputData} */ private static iterParse; /** * Parse the raw WhoIs text and return extracted values * * @param rawData raw text from WhoIs server * @param outputData Data which needs to be extracted from the raw text (key/value pairs). Keys are used to extract from raw text and values are filled. * @returns Filled {@link outputData} */ static parseData(rawData: string, outputData: any | null): any; } /** * Connects to the provided {@link server}:{@link port} through TCP (through a proxy if a proxy is given), run the WhoIs query and returns the response * * @param domain Domain name * @param queryOptions Query options which can be used with the specific WhoIs server to get the complete response * @param server WhoIs server * @param port WhoIs server port * @param encoding Encoding used by the WhoIs server * @param proxy {@link ProxyData} * @returns The {string} WhoIs response for the query. Empty string is returned for errors */ export declare function tcpWhois(domain: string, queryOptions: string, server: string, port: number, encoding: string, proxy: ProxyData | null): Promise<string>; /** * Collect WhoIs data for the mentioned {@link domain}. Parse the received response if {@link parse} is true, accordingly. * * @param domain Domain name * @param parse Whether the raw text needs to be parsed/formatted or not * @param options {@link WhoIsOptions} * @param logger * @returns {@link WhoIsResponse} */ export declare function whois(domain: string, parse?: boolean, options?: WhoIsOptions | null, logger?: LoggerInterface): Promise<WhoIsResponse>; /** * Collects (and parse/format if set to be true) for the provided {@link domains}. If {@link parallel} is set to be true, multiple threads will be used to batch process the domains according to {@link threads} mentioned. * If <i>options.parsedData</i> is mentioned, then it will be used to parse <b>all</b> the responses. * If a proxy is mentioned in {@link options}, then the proxy will be used to collect <b>all</b> the WhoIs data. * * @param domains Domains Names * @param parallel Whether data should be collected in parallel or not * @param threads Batch size (for parallel processing) * @param parse Whether the raw text needs to be parsed/formatted or not * @param options {@link WhoIsOptions} * @returns Array of {@link WhoIsResponse} for all the domains. Order is not guaranteed */ export declare function batchWhois(domains: string[], parallel?: boolean, threads?: number, parse?: boolean, options?: WhoIsOptions | null): Promise<WhoIsResponse[]>;