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

haraka-net-utils

v1.7.1

Published

haraka network utilities

Downloads

10,490

Readme

CI Code Coverage Code Climate

NPM

Net-Utils

This module provides network utility functions.

Usage

const net_utils = require('haraka-net-utils');

ip_to_long

// Convert IPv4 to long
const long = net_utils.ip_to_long('11.22.33.44') // 185999660

long_to_ip

// Convert long to IPv4
const ip = net_utils.long_to_ip(185999660) // 11.22.33.44

dec_to_hex

// Convert decimal to hex
const hex = net_utils.dec_to_hex(20111104) // 132df00

hex_to_dec

// Convert hex to decimal
const dec = net_utils.hex_to_dec('132df00') // 20111104

is_local_ipv4

// Is IPv4 address on a local network?
net_utils.is_local_ipv4('127.0.0.200') // true (localhost)
net_utils.is_local_ipv4('169.254.0.0') // true (link local)
net_utils.is_local_ipv4('226.0.0.1') // false

is_private_ipv4

// Is IPv4 address in RFC 1918 reserved private address space?
net_utils.is_private_ipv4('10.0.0.0') // true
net_utils.is_private_ipv4('192.168.0.0') // true
net_utils.is_private_ipv4('172.16.0.0') // true

is_local_ipv6

// Is IPv6 addr on local network?
net_utils.is_local_ipv6('::1') // true (localhost)
net_utils.is_local_ipv6('fe80::') // true (link local)
net_utils.is_local_ipv6('fc00::') // true (unique local)
net_utils.is_local_ipv6('fd00::') // true (unique local)

is_private_ip

Determines if an IPv4 or IPv6 address is on a "private" network. For IPv4, returns true if is_private_ipv4 or is_local_ipv4 are true For IPv6, returns true if is_local_ipv6 is true

is_local_host

Checks to see if a host name matches our server hostname or resolves to any local ip. Local IPs include those bound to a local network interface and public IPs discovered with STUN.

is_local_ip

Checks to see if an IP is bound locally or an IPv4 or IPv6 localhost address.

ip_in_list

// searches for 'ip' as a hash key in the list object or array
// ip can be a host, an IP, or an IPv4 or IPv6 range
net_utils.ip_in_list(object, ip)
net_utils.ip_in_list(array, ip)
net_utils.ip_in_list(tls.no_tls_hosts, '127.0.0.5')

get_ips_by_host

Returns an array of all the IPv4 and IPv6 addresses of the provided hostname.

try {
  const ips = await net_utils.get_ips_by_host(domain)
  for (const ip of ips) {
    // do something with the IPs
  }
} catch (err) {
  // handle any errors
}

get_mx

try {
  const mxList = await net_utils.get_mx(domain)
  for (const mx of mxList) {
    // do something with each mx
  }
} catch (err) {
  // handle any errors
}

HarakaMx

An object class representing a MX. HarakaMx objects may contain the following properties:

{
  exchange: '', // required: a FQDN or IP address
  path: '', // the file path to a socket
  priority: 0, // integer, a MX priority.
  port: 25, // integer: an alternate port
  bind: '', // an outbound IP address to bind to
  bind_helo: '', // an outbound helo hostname
  using_lmtp: false, // boolean, specify LMTP delivery
  auth_user: '', // an AUTH username (required if AUTH is desired)
  auth_pass: '', // an AUTH password (required if AUTH is desired)
  auth_type: '', // an AUTH type that should be used with the MX.
  from_dns: '', // the DNS name from which the MX was queried
}

Create a HarakaMx object in The Usual Way:

const nu = require('haraka-net-utils')
const myMx = new nu.HarakaMx(parameter)

The parameter can be one of:

  • A string in any of the following formats:
    • hostname
    • hostname:port
    • IPv4
    • IPv4:port
    • IPv6
  • A URL string
    • smtp://mail.example.com:25
    • lmtp://int-mail.example.com:24
    • smtp://user:[email protected]:587
  • An object, containing at least an exchange, and any of the other properties listed at the top of this section.

An optional second parameter is an alias for from_dns.