New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

haraka-net-utils

Package Overview
Dependencies
Maintainers
4
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

haraka-net-utils - npm Package Compare versions

Comparing version 1.3.4 to 1.3.5

8

Changes.md

@@ -5,2 +5,10 @@

#### 1.3.5 - 2022-05-27
- chore(ci): use shared GHA workflows
- style(es6): use dns.promises internally
- dep(async): replace async dependency with Promise.all
- doc(README): use code fences around examples (vs indention)
#### 1.3.4 - 2022-01-05

@@ -7,0 +15,0 @@

72

index.js
'use strict';
// node.js built-ins
const dns = require('dns');
const dns = require('dns').promises;
const net = require('net');

@@ -10,3 +10,2 @@ const os = require('os');

// npm modules
const async = require('async');
const ipaddr = require('ipaddr.js');

@@ -322,47 +321,30 @@ const sprintf = require('sprintf-js').sprintf;

exports.get_ips_by_host = function (hostname, done) {
const ips = new Set();
const errors = [];
const ips = new Set()
const errors = []
const promises = []
function resolve4 (iter_done) {
dns.resolve4(hostname, (err, addrs) => {
if (err) {
errors.push(err);
return iter_done();
}
async function resolveAny (ver) {
try {
const addrs = await dns[`resolve${ver}`](hostname)
for (const a of addrs) {
ips.add(a);
}
iter_done(null, true);
});
return addrs
}
catch (err) {
errors.push(err);
}
}
function resolve6 (iter_done) {
dns.resolve6(hostname, (err, addrs) => {
if (err) {
errors.push(err);
return iter_done();
}
for (const a of addrs) {
ips.add(a);
}
iter_done(null, true);
});
}
promises.push(resolveAny('4'))
promises.push(resolveAny('6'))
// if multiple IPs are returned in the iterations, then the async_list
// will be an array of nested arrays. Not what we want. Instead,
// return the unique IPs in the combined flattened array.
// for callback API
if (done) {
async.parallel([ resolve4, resolve6 ], function (err, async_list) {
done(errors, Array.from(ips));
})
Promise.all(promises).then((r) => { done(errors, Array.from(ips)) })
return
}
else {
return new Promise((resolve, reject) => {
async.parallel([ resolve4, resolve6 ], function (err, async_list) {
if (!ips.size && errors?.length) return reject(errors)
resolve(Array.from(ips));
})
})
}
// promise API
return Promise.all(promises).then(r => { return Array.from(ips) })
}

@@ -471,5 +453,4 @@

try {
dns.resolveMx(domain, (err, addresses) => {
dns.resolveMx(domain)
.then(addresses => {
if (addresses && addresses.length) {

@@ -481,8 +462,7 @@ for (const addr of addresses) {

cb(err, mxs);
cb(null, mxs);
})
}
catch (e) {
cb(e, mxs)
}
.catch(err => {
cb(err)
})
}
{
"name": "haraka-net-utils",
"version": "1.3.4",
"version": "1.3.5",
"description": "haraka network utilities",

@@ -10,3 +10,2 @@ "main": "index.js",

"lintfix": "npx eslint --fix *.js test",
"cover": "NODE_ENV=cov npx nyc --reporter=lcovonly npm run test",
"versions": "npx dependency-version-checker check"

@@ -27,3 +26,3 @@ },

"engines": {
"node": ">= v14.18.2"
"node": ">= v14.0.0"
},

@@ -35,9 +34,8 @@ "bugs": {

"devDependencies": {
"eslint": ">=7.32.0",
"mocha": "*",
"eslint": "8",
"mocha": "9",
"eslint-plugin-haraka": "*"
},
"dependencies": {
"async": "^3.2.2",
"haraka-config": ">=1.0.11",
"haraka-config": "^1.0.11",
"haraka-tld": "*",

@@ -44,0 +42,0 @@ "ipaddr.js": "^2.0.1",

@@ -1,3 +0,2 @@

![CI Linux][ci-img]
![CI Windows][ci-win-img]
[![CI][ci-img]][ci-url]
[![Code Coverage][cov-img]][cov-url]

@@ -14,51 +13,65 @@ [![Code Climate][clim-img]][clim-url]

const net_utils = require('haraka-net-utils');
`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
```js
// 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
```js
// 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
```js
// 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
```js
// 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
```js
// 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
```js
// 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)
```js
// 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
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

@@ -75,20 +88,23 @@ ### is_local_host

// 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');
```js
// 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_mx
net_utils.get_mx(domain, (err, mxList) => {
if (err) // handle any errors
for (const mx of mxList) {
// do something with each mx
}
})
```js
net_utils.get_mx(domain, (err, mxList) => {
if (err) // handle any errors
for (const mx of mxList) {
// do something with each mx
}
})
```
[ci-img]: https://github.com/haraka/haraka-net-utils/workflows/CI%20Linux/badge.svg
[ci-win-img]: https://github.com/haraka/haraka-net-utils/workflows/CI%20Windows/badge.svg
[ci-img]: https://github.com/haraka/haraka-net-utils/actions/workflows/ci.yml/badge.svg
[ci-url]: https://github.com/haraka/haraka-net-utils/actions/workflows/ci.yml
[cov-img]: https://codecov.io/github/haraka/haraka-net-utils/coverage.svg

@@ -95,0 +111,0 @@ [cov-url]: https://codecov.io/github/haraka/haraka-net-utils

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc