@k03mad/dns-leak 1.1.0 → 1.2.0

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.
@@ -22,7 +22,7 @@ jobs:
22
22
  uses: actions/checkout@v4
23
23
 
24
24
  - name: Install NodeJS
25
- uses: actions/setup-node@v3
25
+ uses: actions/setup-node@v4
26
26
  with:
27
27
  node-version-file: '.nvmrc'
28
28
 
package/app/api/IPLeak.js CHANGED
@@ -3,6 +3,7 @@ import {customAlphabet} from 'nanoid';
3
3
  import {lowercase, numbers} from 'nanoid-dictionary';
4
4
 
5
5
  import {sleep} from '../helpers/promise.js';
6
+ import * as spinner from '../helpers/spinner.js';
6
7
 
7
8
  /** */
8
9
  export default class IPLeak {
@@ -93,15 +94,25 @@ export default class IPLeak {
93
94
  /**
94
95
  * @param {object} [opts]
95
96
  * @param {string} [opts.session]
97
+ * @param {boolean} [opts.isSpinnerEnabled]
96
98
  * @returns {Promise<object>}
97
99
  */
98
- async getDnsInfoMulti({session = this._dnsSessionString} = {}) {
99
- const arrayFromLen = Array.from({length: this._dnsRequestsCount});
100
+ async getDnsInfoMulti({isSpinnerEnabled, session = this._dnsSessionString} = {}) {
101
+ const spinnerName = 'dnsReq';
102
+ const arrayFromLen = Array.from({length: this._dnsRequestsCount - 1});
100
103
 
101
- await Promise.all(arrayFromLen.map(() => this.getDnsInfoOnce({session})));
102
- await sleep(this._dnsRequestsWaitBeforeLastMs);
104
+ spinner.start(spinnerName, isSpinnerEnabled);
105
+
106
+ await Promise.all(arrayFromLen.map(async () => {
107
+ await this.getDnsInfoOnce({session});
108
+ spinner.count(spinnerName, this._dnsRequestsCount);
109
+ }));
103
110
 
111
+ spinner.text(spinnerName, 'Wait for last request');
112
+ await sleep(this._dnsRequestsWaitBeforeLastMs);
104
113
  const info = await this.getDnsInfoOnce({session});
114
+
115
+ spinner.stop(spinnerName);
105
116
  return info;
106
117
  }
107
118
 
@@ -1,14 +1,5 @@
1
- import chalk from 'chalk';
2
-
3
- const {bgBlackBright, magenta} = chalk;
4
-
5
1
  /**
6
2
  * @param {any} msg
7
3
  */
8
4
  // eslint-disable-next-line no-console
9
- export const log = (...msg) => console.log(...msg);
10
-
11
- /**
12
- * @param {any} header
13
- */
14
- export const logHeader = header => log(`\n${bgBlackBright(magenta(` ${header} `))}\n`);
5
+ export const log = (...msg) => msg.forEach(elem => console.log(elem));
@@ -0,0 +1,49 @@
1
+ import ora from 'ora';
2
+
3
+ import {bar} from './text.js';
4
+
5
+ export const spinner = {};
6
+
7
+ /**
8
+ * @param {string} name
9
+ * @param {boolean} active
10
+ */
11
+ export const start = (name, active) => {
12
+ if (active) {
13
+ spinner[name] = {
14
+ instance: ora().start(),
15
+ counter: 0,
16
+ };
17
+
18
+ return spinner[name].instance;
19
+ }
20
+
21
+ spinner[name] = {instance: {stop: () => ''}};
22
+ };
23
+
24
+ /**
25
+ * @param {string} name
26
+ * @param {string} msg
27
+ */
28
+ export const text = (name, msg) => {
29
+ spinner[name].instance.text = bar(msg);
30
+ };
31
+
32
+ /**
33
+ * @param {string} name
34
+ * @param {number} total
35
+ */
36
+ export const count = (name, total) => {
37
+ spinner[name].counter++;
38
+
39
+ const len = `${String(spinner[name].counter).padStart(String(total).length, '0')}/${total}`;
40
+ const percent = `${String((spinner[name].counter * 100 / total).toFixed(0)).padStart(2, '0')}%`;
41
+ text(name, `${len} [${percent}]`);
42
+ };
43
+
44
+ /**
45
+ * @param {string} name
46
+ */
47
+ export const stop = name => {
48
+ spinner[name].instance.stop();
49
+ };
@@ -3,7 +3,17 @@
3
3
  import chalk from 'chalk';
4
4
  import clm from 'country-locale-map';
5
5
 
6
- const {blue, green} = chalk;
6
+ const {bgBlackBright, blue, green, magenta, yellow} = chalk;
7
+
8
+ /**
9
+ * @param {any} msg
10
+ */
11
+ export const header = msg => bgBlackBright(magenta(` ${msg} `));
12
+
13
+ /**
14
+ * @param {any} msg
15
+ */
16
+ export const bar = msg => yellow(msg);
7
17
 
8
18
  /**
9
19
  * @param {object} [ipInfo]
package/app/index.js CHANGED
@@ -1,22 +1,37 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import IPLeak from './api/IPLeak.js';
4
- import {formatIpInfo} from './helpers/ip.js';
5
- import {log, logHeader} from './helpers/log.js';
4
+ import {log} from './helpers/log.js';
5
+ import * as spinner from './helpers/spinner.js';
6
+ import {formatIpInfo, header} from './helpers/text.js';
6
7
 
7
8
  const api = new IPLeak();
8
9
 
9
10
  const currentIpInfo = await api.getIpInfo();
10
11
 
11
- logHeader('IP');
12
- log(formatIpInfo(currentIpInfo));
13
- logHeader('DNS');
12
+ log(
13
+ '',
14
+ header('IP'),
15
+ '',
16
+ formatIpInfo(currentIpInfo),
17
+ '',
18
+ header('DNS'),
19
+ '',
20
+ );
14
21
 
15
- const dnsInfo = await api.getDnsInfoMulti();
22
+ const dnsInfo = await api.getDnsInfoMulti({isSpinnerEnabled: true});
16
23
  const dnsIps = [...new Set(Object.keys(dnsInfo.ip))];
17
24
 
18
- const dnsData = await Promise.all(dnsIps.map(ip => api.getIpInfo({ip})));
25
+ spinner.start(currentIpInfo.ip, true);
26
+
27
+ const dnsData = await Promise.all(dnsIps.map(async ip => {
28
+ const data = await api.getIpInfo({ip});
29
+ spinner.count(currentIpInfo.ip, dnsIps.length);
30
+ return data;
31
+ }));
32
+
33
+ spinner.stop(currentIpInfo.ip);
19
34
 
20
35
  dnsData
21
36
  .sort((a, b) => a?.ip?.localeCompare(b?.ip))
22
- .forEach(data => log(formatIpInfo(data), '\n'));
37
+ .forEach(data => log(formatIpInfo(data), ''));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k03mad/dns-leak",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "DNS leak test",
5
5
  "maintainers": [
6
6
  "Kirill Molchanov <k03.mad@gmail.com"
@@ -18,7 +18,8 @@
18
18
  "chalk": "5.3.0",
19
19
  "country-locale-map": "1.8.15",
20
20
  "nanoid": "5.0.2",
21
- "nanoid-dictionary": "5.0.0-beta.1"
21
+ "nanoid-dictionary": "5.0.0-beta.1",
22
+ "ora": "7.0.1"
22
23
  },
23
24
  "devDependencies": {
24
25
  "@k03mad/eslint-config": "13.3.1",