pubface 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +25 -1
- package/package.json +2 -1
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const packageData = require('./package.json');
|
|
|
5
5
|
const dns = require('dns').promises;
|
|
6
6
|
const os = require('os');
|
|
7
7
|
const net = require('net');
|
|
8
|
+
const ipaddr = require('ipaddr.js');
|
|
8
9
|
|
|
9
10
|
const RESOLV_URL = process.env.RESOLV_URL || 'https://api.nodemailer.com/';
|
|
10
11
|
const RESOLV_TIMEOUT = Number(process.env.RESOLV_TIMEOUT) || 5;
|
|
@@ -12,6 +13,29 @@ const RESOLV_TIMEOUT = Number(process.env.RESOLV_TIMEOUT) || 5;
|
|
|
12
13
|
const RESOLV_TIMEOUT_SEC = RESOLV_TIMEOUT * 1000;
|
|
13
14
|
const DNS_CACHE = {};
|
|
14
15
|
|
|
16
|
+
function getPtrAddr(address) {
|
|
17
|
+
let parsed = ipaddr.parse(address);
|
|
18
|
+
if (net.isIPv4(address)) {
|
|
19
|
+
return parsed.toByteArray().reverse().join('.') + '.in-addr.arpa.';
|
|
20
|
+
}
|
|
21
|
+
if (net.isIPv6(address)) {
|
|
22
|
+
return (
|
|
23
|
+
parsed
|
|
24
|
+
.toByteArray()
|
|
25
|
+
.map(nr => (nr < 0x0a ? '0' : '') + nr.toString(16))
|
|
26
|
+
.join('')
|
|
27
|
+
.split('')
|
|
28
|
+
.reverse()
|
|
29
|
+
.join('.') + '.ip6.arpa.'
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function resolvePtr(address) {
|
|
35
|
+
let ptrAddress = getPtrAddr(address);
|
|
36
|
+
return await dns.resolvePtr(ptrAddress);
|
|
37
|
+
}
|
|
38
|
+
|
|
15
39
|
async function updateDns() {
|
|
16
40
|
let now = new Date();
|
|
17
41
|
|
|
@@ -136,7 +160,7 @@ async function resolveIP(localAddress, family) {
|
|
|
136
160
|
}
|
|
137
161
|
|
|
138
162
|
try {
|
|
139
|
-
let name = await
|
|
163
|
+
let name = await resolvePtr(data.ip);
|
|
140
164
|
if (name && name.length) {
|
|
141
165
|
data.name = name[0];
|
|
142
166
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pubface",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Resolve public network interfaces for current machine",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"pubface": "bin/pubface.js"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
+
"ipaddr.js": "2.0.1",
|
|
21
22
|
"nodemailer": "6.7.1"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|