pubface 1.0.0 → 1.0.3
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/README.md +6 -0
- package/entitlements.mac.plist +16 -0
- package/index.js +36 -6
- package/package.json +21 -3
package/README.md
CHANGED
|
@@ -27,6 +27,12 @@ Install the command
|
|
|
27
27
|
$ npm install -g pubface
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
Or alternatively download the latest executable if you do not have Node.js or NPM installed
|
|
31
|
+
|
|
32
|
+
- [MacOS](https://github.com/postalsys/pubface/releases/latest/download/pubface.pkg)
|
|
33
|
+
- [Linux](https://github.com/postalsys/pubface/releases/latest/download/pubface.tar.gz)
|
|
34
|
+
- [Window](https://github.com/postalsys/pubface/releases/latest/download/pubface.exe)
|
|
35
|
+
|
|
30
36
|
Use it to get an array of interfaces
|
|
31
37
|
|
|
32
38
|
```
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>com.apple.security.cs.allow-jit</key>
|
|
6
|
+
<true/>
|
|
7
|
+
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
|
|
8
|
+
<true/>
|
|
9
|
+
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
|
|
10
|
+
<true/>
|
|
11
|
+
<key>com.apple.security.cs.disable-library-validation</key>
|
|
12
|
+
<true/>
|
|
13
|
+
<key>com.apple.security.network.client</key>
|
|
14
|
+
<true/>
|
|
15
|
+
</dict>
|
|
16
|
+
</plist>
|
package/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const fetchUrl = require('nodemailer/lib/fetch');
|
|
4
4
|
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
|
|
|
@@ -77,9 +101,15 @@ function getPublicInterfaces() {
|
|
|
77
101
|
let publicInterfaces = { IPv4: [], IPv6: [] };
|
|
78
102
|
Object.keys(interfaces)
|
|
79
103
|
.flatMap(iface => interfaces[iface].filter(entry => !entry.internal).map(entry => Object.assign({ iface }, entry)))
|
|
80
|
-
.forEach(
|
|
81
|
-
|
|
82
|
-
|
|
104
|
+
.forEach(originalEntry => {
|
|
105
|
+
let entry = Object.assign({}, originalEntry);
|
|
106
|
+
|
|
107
|
+
let family = typeof entry.family === 'number' ? `IPv${entry.family}` : entry.family;
|
|
108
|
+
if (entry.family !== family) {
|
|
109
|
+
entry.family = family;
|
|
110
|
+
}
|
|
111
|
+
if (Array.isArray(publicInterfaces[family])) {
|
|
112
|
+
publicInterfaces[family].push(entry);
|
|
83
113
|
}
|
|
84
114
|
});
|
|
85
115
|
return publicInterfaces;
|
|
@@ -100,7 +130,7 @@ async function timedFunction(prom, timeout, localAddress) {
|
|
|
100
130
|
|
|
101
131
|
async function resolveIP(localAddress, family) {
|
|
102
132
|
let data = await new Promise((resolve, reject) => {
|
|
103
|
-
let req =
|
|
133
|
+
let req = fetchUrl(RESOLV_URL, {
|
|
104
134
|
userAgent: `${packageData.name}/${packageData.version}`,
|
|
105
135
|
tls: {
|
|
106
136
|
host: DNS_CACHE[family] && DNS_CACHE[family].host,
|
|
@@ -136,7 +166,7 @@ async function resolveIP(localAddress, family) {
|
|
|
136
166
|
}
|
|
137
167
|
|
|
138
168
|
try {
|
|
139
|
-
let name = await
|
|
169
|
+
let name = await resolvePtr(data.ip);
|
|
140
170
|
if (name && name.length) {
|
|
141
171
|
data.name = name[0];
|
|
142
172
|
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pubface",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Resolve public network interfaces for current machine",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"build-dist": "pkg package.json"
|
|
8
9
|
},
|
|
9
10
|
"keywords": [],
|
|
10
11
|
"author": "Postal Systems OÜ",
|
|
11
12
|
"license": "MIT",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/postalsys/pubface/issues"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/postalsys/pubface",
|
|
12
17
|
"bin": {
|
|
13
18
|
"pubface": "bin/pubface.js"
|
|
14
19
|
},
|
|
15
20
|
"dependencies": {
|
|
16
|
-
"
|
|
21
|
+
"ipaddr.js": "2.0.1",
|
|
22
|
+
"nodemailer": "6.7.5"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"pkg": "5.7.0"
|
|
26
|
+
},
|
|
27
|
+
"pkg": {
|
|
28
|
+
"assets": [
|
|
29
|
+
"LICENSE.txt"
|
|
30
|
+
],
|
|
31
|
+
"_targets": [
|
|
32
|
+
"node16-macos-x64"
|
|
33
|
+
],
|
|
34
|
+
"outputPath": "dist"
|
|
17
35
|
}
|
|
18
36
|
}
|