is-private-host
Version:
Check if a hostname or URL resolves to a private IP address
135 lines (122 loc) • 3.64 kB
text/typescript
import type {LookupAddress} from 'node:dns'
/**
* Resolve result for a given hostname
*
* @public
*/
export declare interface HostResolveInfo {
isPrivate: boolean
addresses: LookupAddress[]
}
/**
* Determines if a the given hostname resolves to a "private" IP address
*
* @param hostname - Hostname to check
* @returns Promise resolving to true if the hostname resolves to a private IP address, false otherwise
* @public
*/
export declare function isPrivateHost(hostname: string): Promise<boolean>
/**
* Determines if a the given hostname resolves to a "private" IP address
*
* @param hostname - Hostname to check
* @param options - Options for the resolve operation
* @returns Promise resolving to true if the hostname resolves to a private IP address, false otherwise
* @public
*/
export declare function isPrivateHost(
hostname: string,
options: Record<string, never>,
): Promise<boolean>
/**
* Determines if a the given hostname resolves to a "private" IP address
*
* @param hostname - Hostname to check
* @param options - Options for the resolve operation
* @returns Promise resolving to true if the hostname resolves to a private IP address, false otherwise
* @public
*/
export declare function isPrivateHost(
hostname: string,
options: {
withResolveInfo: false
},
): Promise<boolean>
/**
* Determines if a the given hostname resolves to a "private" IP address
*
* @param hostname - Hostname to check
* @param options - Options for the resolve operation
* @returns Promise resolving to an object containing the resolve information
* @public
*/
export declare function isPrivateHost(
hostname: string,
options: {
withResolveInfo: true
},
): Promise<HostResolveInfo>
/**
* Checks if an IP address falls within a private/reserved range.
*
* @param ipAddress - The IP address to check. Can be either IPv4 or IPv6.
* @returns True if the IP address is private/reserved, false otherwise.
* @public
*/
export declare function isPrivateIP(ipAddress: string): boolean
/**
* Determines if a the given URL resolves to a "private" IP address
*
* @param url - URL to check
* @returns Promise resolving to true if the URL resolves to a private IP address, false otherwise
* @public
*/
export declare function isPrivateUrl(url: string): Promise<boolean>
/**
* Determines if a the given URL resolves to a "private" IP address
*
* @param url - URL to check
* @param options - Options for the resolve operation
* @returns Promise resolving to true if the URL resolves to a private IP address, false otherwise
* @public
*/
export declare function isPrivateUrl(url: string, options: Record<string, never>): Promise<boolean>
/**
* Determines if a the given URL resolves to a "private" IP address
*
* @param url - URL to check
* @param options - Options for the resolve operation
* @returns Promise resolving to true if the URL resolves to a private IP address, false otherwise
* @public
*/
export declare function isPrivateUrl(
url: string,
options: {
withResolveInfo: false
},
): Promise<boolean>
/**
* Determines if a the given URL resolves to a "private" IP address
*
* @param url - URL to check
* @param options - Options for the resolve operation
* @returns Promise resolving to an object containing the resolve information
* @public
*/
export declare function isPrivateUrl(
url: string,
options: {
withResolveInfo: true
},
): Promise<UrlResolveInfo>
/**
* Resolve result for a given URL
*
* @public
*/
export declare interface UrlResolveInfo {
isPrivate: boolean
parsedUrl: URL
addresses: LookupAddress[]
}
export {}