1 | # mb-network
|
2 |
|
3 | [![npm version](https://img.shields.io/badge/npm-v1.0.3-orange)](https://www.npmjs.org/package/mb-network)
|
4 | [![install size](https://packagephobia.com/badge?p=mb-network)](https://packagephobia.com/result?p=mb-network)
|
5 |
|
6 | Class based Network Library for Javascript
|
7 |
|
8 | ## Install
|
9 | ```bash
|
10 | $ npm i mb-network
|
11 | ```
|
12 |
|
13 | ## Basic Example
|
14 | ```js
|
15 | import { IP, Subnet } from 'mb-network'
|
16 |
|
17 | const asset = new IP('10.0.0.63')
|
18 | const subnet = new Subnet(Subnet.calcNetworkAddress(asset, 24), 24)
|
19 |
|
20 | console.log(subnet.possibleHostCount())
|
21 | ```
|
22 | Output:
|
23 | ```bash
|
24 | $ 254
|
25 | ```
|
26 |
|
27 | ## Class Parameters
|
28 | - IP(string) `f.e. => '192.168.1.7'`
|
29 | - Subnet(IP, number) `f.e. => new IP('192.168.0.0'), 16`
|
30 | #### note: The IP in the first Subnet parameter should be the network-address!
|
31 |
|
32 | ## Methods
|
33 | ### IP
|
34 | - `ip.asBinaryArray()`, returns the IP as an Array of binary octets.
|
35 | - `ip.asDecimalArray()`, returns the IP as an Array of decimal octets.
|
36 | - `ip.toString()`, returns the IP as a string.
|
37 | - static `IP.fromBinaryOctetArray(Array)`, returns an IP from an Array of binary octets.
|
38 | - static `IP.isSyntaxValid(string)`, returns true if the given string has a valid IP syntax, otherwise false.
|
39 | ### Subnet
|
40 | - `subnet.networkAddress`, getter of the network-address (returns an IP).
|
41 | - `subnet.broadcast()`, returns the broadcast-address as an IP.
|
42 | - `subnet.getDecimalNetworkMask()`, returns the subnet-mask as an Array of decimal octets.
|
43 | - `subnet.possibleHostCount()`, returns the number of possible hosts in the Subnet.
|
44 | - `subnet.getHostAddresses()`, returns an Array of all possible hosts in the Subnet as IP's.
|
45 | - `subnet.toString()`, returns the Subnet as a string.
|
46 | - static `Subnet.calcNetworkAddress(IP, number)`, returns the network-address for the combination of an IP and a suffix as an IP.
|
47 |
|
48 |
|
49 |
|