Installations
npm install ipv4-util
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
19.7.0
NPM Version
8.19.2
Score
73.3
Supply Chain
98.5
Quality
75.5
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Download Statistics
Total Downloads
846
Last Day
7
Last Week
12
Last Month
27
Last Year
117
Bundle Size
4.84 kB
Minified
1.70 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.3.4
Package Id
ipv4-util@0.3.4
Unpacked Size
23.12 kB
Size
6.05 kB
File Count
8
NPM Version
8.19.2
Node Version
19.7.0
Publised On
25 Mar 2023
Total Downloads
Cumulative downloads
Total Downloads
846
Last day
0%
7
Compared to previous day
Last week
33.3%
12
Compared to previous week
Last month
200%
27
Compared to previous month
Last year
-84%
117
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
2
ipv4-util
See documentation
The Date
object of IPv4
A type representing IPv4 protocol addresses.
- Store IPv4's as uint32
- Perform operations
- Handle type conversions (
uint32
,string
,IPv4
) - Plugin system for Hardware functionality (fetching, process spawning)
Install
npm i ipv4-util
Setup
Require the IPv4 type
1const { IPv4 } = require('ipv4-util');
Create an IPv4 instance Multiple types are accepted
1const ip = IPv4.from('192.168.1.1'); // From String 2// IPv4.from(0xC0A80101); // From uint32 3// IPv4.from(IPv4.from('192.168.1.1')); // From other IPv4 instance
Display the IPv4 instance in the console
1ip.log();
Utilities
Get the IPv4 instance as a string
1IPv4.from('192.168.1.1').toString(); // '192.168.1.1'
Get the IPv4 instance as a full uint32
1IPv4.from('192.168.1.1').u32(); // 0xC0A80101
Get a single byte of the IPv4 instance
1const ip = IPv4.from('192.168.1.1'); 2 3const msb_byte = ip.u8(3); // 192 4// ... // ip.u8(2); // 168 5// ... // ip.u8(1); // 1 6const lsb_byte = ip.u8(0); // 1
You can copy the IPv4 instance
1IPv4.from('192.168.1.1').copy(); // A copy of the instance
Mask Utils
1IPv4.from('255.255.255.0').getRange(); // 24
Math
Basic binary AND OR XOR
operations are provided
See documentation for other math operations
Again multiple types are accepted
1ip.and('255.255.255.0'); // From String 2// ip.and(0xFFFFFF00); // From uint32 3// ip.and(IPv4.from('255.255.255.0')); // From other IPv4 instance
Math functions are all chainable
1ip.and(/* */).or(/* */).xor(/* */).add(/* */).log();
You can use copy to avoid affecting the caller IPv4 instance
1const ip = IPv4.from('192.168.1.1') 2 3const mask = ip.copy().and('255.255.255.0');
Custom operations can be implemented with the op
method
It is used here to create a bit flip operation
1ip.op(ip => ~ip);
Iterators
Iterate through all usable hosts
1// with Default gateway and broadcast address 2// Iterate from 10.0.0.1 to 10.0.0.254 3for (let ip = IPv4.from('10.0.0.1'); ip < IPv4.from('10.0.0.255'); ip.add(1)) { 4 ip.log() 5} 6 7// with Default gateway and Mask 8// Iterate from 10.0.0.1 to 10.0.0.254 9for (let ip = IPv4.from('10.0.0.1'); ip < (ip | ~IPv4.from('255.255.255.0')); ip.add(1)) { 10 ip.log() 11} 12
Plugins
Some functionality has to be included
this design is to promote minimalism of the IPv4 type.
This examples fetches the ip from the first active interface
1const { IPv4, Hardware } = require('ipv4-util'); 2 3IPv4.use(Hardware); 4 5const my_interface_ip = IPv4.fromCurrent();
This example pings your local host
1const { IPv4, Hardware } = require('ipv4-util'); 2 3IPv4.use(Hardware); 4 5IPv4.from('127.0.0.1') 6 .ping() 7 .then(({ err }) => { 8 console.log(err ? 'error' : 'success'); 9 });
This example pings all usable hosts in the given range
1const { IPv4, Hardware } = require('ipv4-util'); 2 3IPv4.use(Hardware); 4 5// Iterate through all usable hosts 6// loop ranges from 192.168.1.1 to 192.168.1.254 7for (let ip = IPv4.from('192.168.1.1'); ip < (ip | ~IPv4.from('255.255.255.0')); ip.add(1)) { 8 // Ping `ip` 9 ip.ping() 10 .then(({ err, host }) => { 11 if (err) 12 console.log(`Unable to ping ${host}`) 13 else 14 console.log(`Successfully pinged ${host}`) 15 }) 16}
No vulnerabilities found.
No security vulnerabilities found.