1
- IP Subnet Calculator
2
- =================
3
-
4
- JavaScript class for calculating optimal subnet masks for non-standard IP ranges, e.g. ` 5.4.3.21 - 6.7.8.9 `
1
+ # IP Subnet Calculator
2
+ This module calculates optimal subnet masks for non-standard IP ranges, e.g. ` 5.4.3.21 - 6.7.8.9 `
5
3
6
4
[ View demo] ( http://salieri.github.io/IPSubnetCalculator/ )
7
5
8
6
9
- What does it do?
10
- ----------------
11
-
7
+ ## What does it do?
12
8
* Calculates subnet masks for standard and non-standard IP ranges. For example, ` 10.0.0.5 - 10.0.0.23 ` will result in ` 10.0.0.5/32, 10.0.0.6/31, 10.0.0.8/29, 10.0.0.16/29 ` .
13
9
* Calculates CIDR prefixes from subnet masks, e.g. ` 10.0.0.5/255.255.128.0 ` will result in ` 10.0.0.0/17 ` .
14
10
* Calculates subnet masks from CIDR prefixes, e.g. ` 10.0.0.5/17 ` will result in ` 255.255.128.0 ` .
15
11
16
12
17
- Support
18
- -------
19
-
13
+ ## Support
20
14
* Node.js
21
15
* Direct browser use
22
16
23
17
24
- Installation
25
- ------------
26
-
18
+ ## Installation
27
19
``` sh
28
20
> npm install ip-subnet-calculator
29
21
```
30
22
31
23
32
- Node.js
33
- -------
24
+ ## Node.js
34
25
``` javascript
35
26
import * as IPSubnetCalculator from ' ip-subnet-calculator' ;
36
27
// or: const IPSubnetCalculator = require('ip-subnet-calculator');
@@ -41,9 +32,7 @@ console.log(IpSubnetCalculator.toDecimal('127.0.0.1')); // 2130706433
41
32
console .log (IpSubnetCalculator .calculate (' 5.4.3.21' , ' 6.7.8.9' ));
42
33
```
43
34
44
-
45
- Direct browser use
46
- ------------------
35
+ ## Direct browser use
47
36
``` html
48
37
<script src =' lib/ip-subnet-calculator.browser.js' ></script >
49
38
@@ -56,10 +45,9 @@ Direct browser use
56
45
```
57
46
58
47
59
- API
60
- ---
61
- ### IpSubnetCalculator.calculate(ipStart, ipEnd) ###
48
+ ## API
62
49
50
+ ### IpSubnetCalculator.calculate(ipStart, ipEnd)
63
51
Calculates an optimal set of IP masks for the given IP address range.
64
52
65
53
> *ipStart* (`string|number`) Lowest IP in the range to be calculated in string (`123.123.123.0`) or numeric (`2071689984`) format.
@@ -103,9 +91,7 @@ Each object in question contain the following properties:
103
91
| `invertedMaskStr` | String representation of the inverted prefix mask |
104
92
| `invertedSize` | Size of the inverted prefix max in bits |
105
93
106
-
107
- ### IpSubnetCalculator.calculateSubnetMask(ip, prefixSize) ###
108
-
94
+ ### IpSubnetCalculator.calculateSubnetMask(ip, prefixSize)
109
95
Calculates a subnet mask from CIDR prefix.
110
96
111
97
> *ip* (`string|number`) IP address in string or numeric format
@@ -114,9 +100,7 @@ Calculates a subnet mask from CIDR prefix.
114
100
115
101
The function returns an object containing full description of the IP range, as described in `IpSubnetCalculator.calculate()`.
116
102
117
-
118
- ### IpSubnetCalculator.calculateCIDRPrefix(ip, subnetMask) ###
119
-
103
+ ### IpSubnetCalculator.calculateCIDRPrefix(ip, subnetMask)
120
104
Calculates a CIDR prefix from subnet mask.
121
105
122
106
> *ip* (`string|number`) IP address in string or numeric format
@@ -126,29 +110,26 @@ Calculates a CIDR prefix from subnet mask.
126
110
The function returns an object containing full description of the IP range, as described in `IpSubnetCalculator.calculate()`.
127
111
128
112
129
- ## Test Functions ##
130
-
131
- ### IpSubnetCalculator.isIp(ipStr) ###
113
+ ## Test Functions
132
114
115
+ ### IpSubnetCalculator.isIp(ipStr)
133
116
Tests whether string is an IP address.
134
117
135
118
> *ipStr* (`string`) A string
136
119
137
120
The function returns a `true` if the string is an IP address, `false` otherwise.
138
121
139
- ### IpSubnetCalculator.isDecimalIp(ipNum) ###
140
-
122
+ ### IpSubnetCalculator.isDecimalIp(ipNum)
141
123
Tests whether `ipNum` is a decimal IP address.
142
124
143
125
> *ipNum* (`number`) A number
144
126
145
127
The function returns a `true` if the number is an IP address, `false` otherwise.
146
128
147
129
148
- ## Conversion Functions ##
149
-
150
- ### IpSubnetCalculator.toDecimal(ip) ###
130
+ ## Conversion Functions
151
131
132
+ ### IpSubnetCalculator.toDecimal(ip)
152
133
Calculates a decimal integer from an string IP address.
153
134
154
135
> *ip* (`string|number`) IP address in string format
@@ -159,8 +140,7 @@ of an IP is passed to this function, it is returned unmodified.
159
140
If an invalid value is passed to the function, it will `throw` an `Error` object.
160
141
161
142
162
- ### IpSubnetCalculator.toString(num) ###
163
-
143
+ ### IpSubnetCalculator.toString(num)
164
144
> *num* (`number|string`) Decimal representation of an IP address.
165
145
166
146
The function returns an IP address as a string. If a valid string representation of an IP is passed to this function,
@@ -169,9 +149,7 @@ it is returned unmodified.
169
149
If an invalid value is passed to the function, it will `throw` an `Error` object.
170
150
171
151
172
- License
173
- -------
174
-
152
+ ## License
175
153
[MIT](http://opensource.org/licenses/MIT)
176
154
177
155
0 commit comments