source: trip-planner-front/node_modules/ip/README.md@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.7 KB
Line 
1# IP
2[![](https://badge.fury.io/js/ip.svg)](https://www.npmjs.com/package/ip)
3
4IP address utilities for node.js
5
6## Installation
7
8### npm
9```shell
10npm install ip
11```
12
13### git
14
15```shell
16git clone https://github.com/indutny/node-ip.git
17```
18
19## Usage
20Get your ip address, compare ip addresses, validate ip addresses, etc.
21
22```js
23var ip = require('ip');
24
25ip.address() // my ip address
26ip.isEqual('::1', '::0:1'); // true
27ip.toBuffer('127.0.0.1') // Buffer([127, 0, 0, 1])
28ip.toString(new Buffer([127, 0, 0, 1])) // 127.0.0.1
29ip.fromPrefixLen(24) // 255.255.255.0
30ip.mask('192.168.1.134', '255.255.255.0') // 192.168.1.0
31ip.cidr('192.168.1.134/26') // 192.168.1.128
32ip.not('255.255.255.0') // 0.0.0.255
33ip.or('192.168.1.134', '0.0.0.255') // 192.168.1.255
34ip.isPrivate('127.0.0.1') // true
35ip.isV4Format('127.0.0.1'); // true
36ip.isV6Format('::ffff:127.0.0.1'); // true
37
38// operate on buffers in-place
39var buf = new Buffer(128);
40var offset = 64;
41ip.toBuffer('127.0.0.1', buf, offset); // [127, 0, 0, 1] at offset 64
42ip.toString(buf, offset, 4); // '127.0.0.1'
43
44// subnet information
45ip.subnet('192.168.1.134', '255.255.255.192')
46// { networkAddress: '192.168.1.128',
47// firstAddress: '192.168.1.129',
48// lastAddress: '192.168.1.190',
49// broadcastAddress: '192.168.1.191',
50// subnetMask: '255.255.255.192',
51// subnetMaskLength: 26,
52// numHosts: 62,
53// length: 64,
54// contains: function(addr){...} }
55ip.cidrSubnet('192.168.1.134/26')
56// Same as previous.
57
58// range checking
59ip.cidrSubnet('192.168.1.134/26').contains('192.168.1.190') // true
60
61
62// ipv4 long conversion
63ip.toLong('127.0.0.1'); // 2130706433
64ip.fromLong(2130706433); // '127.0.0.1'
65```
66
67### License
68
69This software is licensed under the MIT License.
70
71Copyright Fedor Indutny, 2012.
72
73Permission is hereby granted, free of charge, to any person obtaining a
74copy of this software and associated documentation files (the
75"Software"), to deal in the Software without restriction, including
76without limitation the rights to use, copy, modify, merge, publish,
77distribute, sublicense, and/or sell copies of the Software, and to permit
78persons to whom the Software is furnished to do so, subject to the
79following conditions:
80
81The above copyright notice and this permission notice shall be included
82in all copies or substantial portions of the Software.
83
84THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
85OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
86MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
87NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
88DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
89OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
90USE OR OTHER DEALINGS IN THE SOFTWARE.
Note: See TracBrowser for help on using the repository browser.