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