Net-Utils
This module provides network utility functions.
Usage
const net_utils = require('haraka-net-utils');
ip_to_long
const long = net_utils.ip_to_long('11.22.33.44')
long_to_ip
const ip = net_utils.long_to_ip(185999660)
dec_to_hex
const hex = net_utils.dec_to_hex(20111104)
hex_to_dec
const dec = net_utils.hex_to_dec('132df00')
is_local_ipv4
net_utils.is_local_ipv4('127.0.0.200')
net_utils.is_local_ipv4('169.254.0.0')
net_utils.is_local_ipv4('226.0.0.1')
is_private_ipv4
net_utils.is_private_ipv4('10.0.0.0')
net_utils.is_private_ipv4('192.168.0.0')
net_utils.is_private_ipv4('172.16.0.0')
is_local_ipv6
net_utils.is_local_ipv6('::1')
net_utils.is_local_ipv6('fe80::')
net_utils.is_local_ipv6('fc00::')
net_utils.is_local_ipv6('fd00::')
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
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) {
}
} catch (err) {
}
get_mx
try {
const mxList = await net_utils.get_mx(domain)
for (const mx of mxList) {
}
} catch (err) {
}
HarakaMx
An object class representing a MX. HarakaMx objects may contain the following properties:
{
exchange: '',
path: '',
priority: 0,
port: 25,
bind: '',
bind_helo: '',
using_lmtp: false,
auth_user: '',
auth_pass: '',
auth_type: '',
from_dns: '',
}
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
- 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.