npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ipv4-util

v0.3.4

Published

See [documentation](https://raw.githack.com/matiasvlevi/ipv4-util/master/docs/index.html)

Downloads

3

Readme

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

const { IPv4 } = require('ipv4-util');

Create an IPv4 instance Multiple types are accepted

const ip = IPv4.from('192.168.1.1');              // From String
//         IPv4.from(0xC0A80101);                 // From uint32
//         IPv4.from(IPv4.from('192.168.1.1'));   // From other IPv4 instance

Display the IPv4 instance in the console

ip.log();

Utilities

Get the IPv4 instance as a string

IPv4.from('192.168.1.1').toString(); // '192.168.1.1'

Get the IPv4 instance as a full uint32

IPv4.from('192.168.1.1').u32();      // 0xC0A80101

Get a single byte of the IPv4 instance

const ip = IPv4.from('192.168.1.1');

const msb_byte = ip.u8(3); // 192
// ... //        ip.u8(2); // 168
// ... //        ip.u8(1); //   1
const lsb_byte = ip.u8(0); //   1

You can copy the IPv4 instance

IPv4.from('192.168.1.1').copy();      // A copy of the instance

Mask Utils

IPv4.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

ip.and('255.255.255.0');               // From String
// ip.and(0xFFFFFF00);                 // From uint32
// ip.and(IPv4.from('255.255.255.0')); // From other IPv4 instance

Math functions are all chainable

ip.and(/* */).or(/* */).xor(/* */).add(/* */).log();

You can use copy to avoid affecting the caller IPv4 instance

const ip = IPv4.from('192.168.1.1')

const 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

ip.op(ip => ~ip);

Iterators

Iterate through all usable hosts

// with Default gateway and broadcast address
// Iterate from 10.0.0.1 to 10.0.0.254
for (let ip = IPv4.from('10.0.0.1'); ip < IPv4.from('10.0.0.255'); ip.add(1)) {
    ip.log()
}

// with Default gateway and Mask
// Iterate from 10.0.0.1 to 10.0.0.254 
for (let ip = IPv4.from('10.0.0.1'); ip < (ip | ~IPv4.from('255.255.255.0')); ip.add(1)) {
    ip.log()
}

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

const { IPv4, Hardware } = require('ipv4-util');

IPv4.use(Hardware);

const my_interface_ip = IPv4.fromCurrent();

This example pings your local host

const { IPv4, Hardware } = require('ipv4-util');

IPv4.use(Hardware);

IPv4.from('127.0.0.1')
    .ping()
    .then(({ err }) => {
        console.log(err ? 'error' : 'success');
    });

This example pings all usable hosts in the given range

const { IPv4, Hardware } = require('ipv4-util');

IPv4.use(Hardware);

// Iterate through all usable hosts
// loop ranges from 192.168.1.1 to 192.168.1.254
for (let ip = IPv4.from('192.168.1.1'); ip < (ip | ~IPv4.from('255.255.255.0')); ip.add(1)) {
    // Ping `ip`
    ip.ping()
      .then(({ err, host }) => {
          if (err) 
            console.log(`Unable to ping ${host}`)
          else 
            console.log(`Successfully pinged ${host}`)
      })
}