|
| 1 | +/// <reference types="node" /> |
| 2 | + |
| 3 | +export interface SubnetInfo { |
| 4 | + networkAddress: string; |
| 5 | + firstAddress: string; |
| 6 | + lastAddress: string; |
| 7 | + broadcastAddress: string; |
| 8 | + subnetMask: string; |
| 9 | + subnetMaskLength: number; |
| 10 | + numHosts: number; |
| 11 | + length: number; |
| 12 | + contains(ip: string): boolean; |
| 13 | +} |
| 14 | + |
| 15 | +/** |
| 16 | +* Check two IP address are the same. |
| 17 | +*/ |
| 18 | +export function isEqual(ip1: string, ip2: string): boolean; |
| 19 | + |
| 20 | +/** |
| 21 | +* Convert an IP string into a buffer. |
| 22 | +*/ |
| 23 | +export function toBuffer(ip: string, buffer?: Buffer, offset?: number): Buffer; |
| 24 | + |
| 25 | +/** |
| 26 | +* Convert an IP buffer into a string. |
| 27 | +*/ |
| 28 | +export function toString(ip: Buffer, offset?: number, length?: number): string; |
| 29 | + |
| 30 | +/** |
| 31 | +* Get the subnet mask from a CIDR prefix length. |
| 32 | +* |
| 33 | +* @param family The IP family is infered from the prefixLength, but can be explicity specified as either "ipv4" or "ipv6". |
| 34 | +*/ |
| 35 | +export function fromPrefixLen(prefixLength: number, family?: "ipv4" | "ipv6"): string; |
| 36 | + |
| 37 | +/** |
| 38 | +* Get the network ID IP address from an IP address and its subnet mask. |
| 39 | +*/ |
| 40 | +export function mask(ip: string, mask: string): string; |
| 41 | + |
| 42 | +/** |
| 43 | +* Get the network ID IP address from an IP address in CIDR notation. |
| 44 | +*/ |
| 45 | +export function cidr(cidr: string): string; |
| 46 | + |
| 47 | +/** |
| 48 | +* Get the bitwise inverse (NOT every octet) of an IP address or subnet mask. |
| 49 | +*/ |
| 50 | +export function not(ip: string): string; |
| 51 | + |
| 52 | +/** |
| 53 | +* Get the bitwise OR of two IP addresses (usually an IP address and a subnet mask). |
| 54 | +*/ |
| 55 | +export function or(ip: string, mask: string): string; |
| 56 | + |
| 57 | +/** |
| 58 | +* Check whether an IP is within a private IP address range. |
| 59 | +*/ |
| 60 | +export function isPrivate(ip: string): boolean; |
| 61 | + |
| 62 | +/** |
| 63 | +* Check whether an IP is within a public IP address range. |
| 64 | +*/ |
| 65 | +export function isPublic(ip: string): boolean; |
| 66 | + |
| 67 | +/** |
| 68 | +* Check whether an IP is a loopback address. |
| 69 | +*/ |
| 70 | +export function isLoopback(ip: string): boolean; |
| 71 | + |
| 72 | +/** |
| 73 | +* Check whether an IP is a IPv4 address. |
| 74 | +*/ |
| 75 | +export function isV4Format(ip: string): boolean; |
| 76 | + |
| 77 | +/** |
| 78 | +* Check whether an IP is a IPv6 address. |
| 79 | +*/ |
| 80 | +export function isV6Format(ip: string): boolean; |
| 81 | + |
| 82 | +/** |
| 83 | +* Get the loopback address for an IP family. |
| 84 | +* |
| 85 | +* @param family The family can be either "ipv4" or "ipv6". Default: "ipv4". |
| 86 | +*/ |
| 87 | +export function loopback(family?: "ipv4" | "ipv6"): string; |
| 88 | + |
| 89 | +/** |
| 90 | +* Get the address for the network interface on the current system with the specified 'name'. |
| 91 | +* If no interface name is specified, the first IPv4 address or loopback address is returned. |
| 92 | +* |
| 93 | +* @param name The name can be any named interface, or 'public' or 'private'. |
| 94 | +* @param family The family can be either "ipv4" or "ipv6". Default: "ipv4". |
| 95 | +*/ |
| 96 | +export function address(name?: "public" | "private" | string, family?: "ipv4" | "ipv6"): string; |
| 97 | + |
| 98 | +/** |
| 99 | +* Convert a string IPv4 IP address to the equivalent long numeric value. |
| 100 | +*/ |
| 101 | +export function toLong(ip: string): number; |
| 102 | + |
| 103 | +/** |
| 104 | +* Convert an IPv4 IP address from its the long numeric value to a string. |
| 105 | +*/ |
| 106 | +export function fromLong(ip: number): string; |
| 107 | + |
| 108 | +/** |
| 109 | +* Get the subnet information. |
| 110 | +* @param ip IP address. |
| 111 | +* @param subnet Subnet address. |
| 112 | +*/ |
| 113 | +export function subnet(ip: string, subnet: string): SubnetInfo; |
| 114 | + |
| 115 | +/** |
| 116 | +* Get the subnet information. |
| 117 | +* @param cidr CIDR address. |
| 118 | +*/ |
| 119 | +export function cidrSubnet(cidr: string): SubnetInfo; |
0 commit comments