@k03mad/dns-leak 1.0.0 → 1.1.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.
package/README.md CHANGED
@@ -1,3 +1,36 @@
1
1
  # DNS leak test
2
2
 
3
- Based on [ipleak.net](https://ipleak.net/)
3
+ Based on: [ipleak.net](https://ipleak.net/) / [API](https://airvpn.org/forums/topic/14737-api/)
4
+
5
+ ## Global
6
+
7
+ ```bash
8
+ npm i @k03mad/dns-leak -g
9
+
10
+ dns-leak
11
+ ```
12
+
13
+ ## API
14
+
15
+ ```bash
16
+ npm i @k03mad/dns-leak
17
+ ```
18
+
19
+ ```js
20
+ import IPLeak from '@k03mad/dns-leak';
21
+
22
+ // default params (details at the link below)
23
+ const api = new IPLeak();
24
+
25
+ // get current external ip info
26
+ await api.getIpInfo();
27
+ // get other ip info
28
+ await api.getIpInfo({ip: '8.8.8.8'});
29
+
30
+ // dns leak check with one request (one request — fewer dns ips)
31
+ await api.getDnsInfoOnce();
32
+ // dns leak check with multi requests
33
+ await api.getDnsInfoMulti();
34
+ ```
35
+
36
+ [Options and parameters with their default values](/app/api/IPLeak.js#L8)
package/app/api/IPLeak.js CHANGED
@@ -2,37 +2,51 @@ import {request, requestCache} from '@k03mad/request';
2
2
  import {customAlphabet} from 'nanoid';
3
3
  import {lowercase, numbers} from 'nanoid-dictionary';
4
4
 
5
+ import {sleep} from '../helpers/promise.js';
6
+
5
7
  /** */
6
8
  export default class IPLeak {
7
9
 
8
10
  /**
9
- * @param {number} [ipRequestsRps]
10
- * @param {number} [ipRequestsCacheExpireMs]
11
- * @param {number} [dnsRequestsCount]
12
- * @param {number} [dnsRequestsRps]
13
- * @param {number} [dnsSessionStringLength]
14
- * @param {number} [dnsUniqStringLength]
11
+ * All args are not required, the default ones works fine
12
+ * @param {object} [opts]
13
+ * @param {number} [opts.dnsRequestsCount] dns leak multi requests count with one session
14
+ * @param {number} [opts.dnsRequestsRps] dns leak requests rps
15
+ * @param {number} [opts.dnsRequestsWaitBeforeLastMs] dns leak multi requests wait before the last request (with all ips gathered)
16
+ * @param {number} [opts.dnsSessionStringLength] dns leak session string length, only works with 40 characters for now
17
+ * @param {number} [opts.dnsUniqStringLength] dns leak unique string length for subdomain
18
+ * @param {number} [opts.ipRequestsCacheExpireMs] ip info requests cache ttl ms for same ip
19
+ * @param {number} [opts.ipRequestsRps] ip info requests rps
15
20
  */
16
- constructor(
17
- ipRequestsRps = 2,
18
- ipRequestsCacheExpireMs = 3_600_000,
21
+ constructor({
19
22
  dnsRequestsCount = 30,
20
23
  dnsRequestsRps = 2,
24
+ dnsRequestsWaitBeforeLastMs = 2000,
21
25
  dnsSessionStringLength = 40,
22
26
  dnsUniqStringLength = 20,
23
- ) {
24
- this._ipRequestsRps = ipRequestsRps;
25
- this._ipRequestsCacheExpireMs = ipRequestsCacheExpireMs;
27
+ ipRequestsCacheExpireMs = 3_600_000,
28
+ ipRequestsRps = 2,
29
+ } = {}) {
26
30
  this._dnsRequestsCount = dnsRequestsCount;
27
31
  this._dnsRequestsRps = dnsRequestsRps;
28
- this._dnsUniqStringLength = dnsUniqStringLength;
32
+ this._dnsRequestsWaitBeforeLastMs = dnsRequestsWaitBeforeLastMs;
29
33
  this._dnsSessionStringLength = dnsSessionStringLength;
34
+ this._dnsUniqStringLength = dnsUniqStringLength;
35
+ this._ipRequestsCacheExpireMs = ipRequestsCacheExpireMs;
36
+ this._ipRequestsRps = ipRequestsRps;
30
37
  }
31
38
 
32
39
  /** */
33
40
  get _endpoints() {
34
41
  return {
35
- info: (ip = '') => `https://ipleak.net/json/${ip}`,
42
+
43
+ /** @param {string} ip */
44
+ ip: ip => `https://ipleak.net/json/${ip}`,
45
+
46
+ /**
47
+ * @param {string} session
48
+ * @param {string} uniq
49
+ */
36
50
  dns: (session, uniq) => `https://${session}-${uniq}.ipleak.net/dnsdetection/`,
37
51
  };
38
52
  }
@@ -48,11 +62,12 @@ export default class IPLeak {
48
62
  }
49
63
 
50
64
  /**
51
- * @param {string} ip
65
+ * @param {object} [opts]
66
+ * @param {string} [opts.ip]
52
67
  * @returns {Promise<object>}
53
68
  */
54
- async getIpInfo(ip) {
55
- const ipEndpoint = this._endpoints.info(ip);
69
+ async getIpInfo({ip = ''} = {}) {
70
+ const ipEndpoint = this._endpoints.ip(ip);
56
71
 
57
72
  const {body} = await requestCache(ipEndpoint, {}, {
58
73
  expire: this._ipRequestsCacheExpireMs,
@@ -63,11 +78,12 @@ export default class IPLeak {
63
78
  }
64
79
 
65
80
  /**
66
- * @param {string} [session]
67
- * @param {string} [uniqString]
81
+ * @param {object} [opts]
82
+ * @param {string} [opts.session]
83
+ * @param {string} [opts.uniqString]
68
84
  * @returns {Promise<object>}
69
85
  */
70
- async getDnsInfoOnce(session = this._dnsSessionString, uniqString = this._dnsUniqString) {
86
+ async getDnsInfoOnce({session = this._dnsSessionString, uniqString = this._dnsUniqString} = {}) {
71
87
  const dnsEndpoint = this._endpoints.dns(session, uniqString);
72
88
 
73
89
  const {body} = await request(dnsEndpoint, {}, {queueBy: session, rps: this._dnsRequestsRps});
@@ -75,14 +91,17 @@ export default class IPLeak {
75
91
  }
76
92
 
77
93
  /**
78
- * @param {string} [session]
94
+ * @param {object} [opts]
95
+ * @param {string} [opts.session]
79
96
  * @returns {Promise<object>}
80
97
  */
81
- async getDnsInfoMulti(session = this._dnsSessionString) {
98
+ async getDnsInfoMulti({session = this._dnsSessionString} = {}) {
82
99
  const arrayFromLen = Array.from({length: this._dnsRequestsCount});
83
- await Promise.all(arrayFromLen.map(() => this.getDnsInfoOnce(session)));
84
100
 
85
- const info = await this.getDnsInfoOnce(session);
101
+ await Promise.all(arrayFromLen.map(() => this.getDnsInfoOnce({session})));
102
+ await sleep(this._dnsRequestsWaitBeforeLastMs);
103
+
104
+ const info = await this.getDnsInfoOnce({session});
86
105
  return info;
87
106
  }
88
107
 
package/app/helpers/ip.js CHANGED
@@ -14,7 +14,7 @@ const {blue, green} = chalk;
14
14
  * @param {string} [ipInfo.isp_name]
15
15
  * @param {string} [ipInfo.region_name]
16
16
  */
17
- export const formatIpInfo = ({city_name, country_code, country_name, ip, isp_name, region_name}) => {
17
+ export const formatIpInfo = ({city_name, country_code, country_name, ip, isp_name, region_name} = {}) => {
18
18
  let output = '';
19
19
 
20
20
  if (ip) {
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @param {number} ms
3
+ * @returns {Promise<void>}
4
+ */
5
+ export const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
package/app/index.js CHANGED
@@ -10,13 +10,12 @@ const currentIpInfo = await api.getIpInfo();
10
10
 
11
11
  logHeader('IP');
12
12
  log(formatIpInfo(currentIpInfo));
13
+ logHeader('DNS');
13
14
 
14
15
  const dnsInfo = await api.getDnsInfoMulti();
15
16
  const dnsIps = [...new Set(Object.keys(dnsInfo.ip))];
16
17
 
17
- logHeader('DNS');
18
-
19
- const dnsData = await Promise.all(dnsIps.map(ip => api.getIpInfo(ip)));
18
+ const dnsData = await Promise.all(dnsIps.map(ip => api.getIpInfo({ip})));
20
19
 
21
20
  dnsData
22
21
  .sort((a, b) => a?.ip?.localeCompare(b?.ip))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k03mad/dns-leak",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "DNS leak test",
5
5
  "maintainers": [
6
6
  "Kirill Molchanov <k03.mad@gmail.com"
@@ -23,7 +23,7 @@
23
23
  "devDependencies": {
24
24
  "@k03mad/eslint-config": "13.3.1",
25
25
  "@microsoft/eslint-formatter-sarif": "3.0.0",
26
- "eslint": "8.53.0",
26
+ "eslint": "8.52.0",
27
27
  "eslint-plugin-import": "2.29.0",
28
28
  "eslint-plugin-jsdoc": "46.8.2",
29
29
  "eslint-plugin-n": "16.2.0",