@k03mad/dns-leak 1.0.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/.editorconfig ADDED
@@ -0,0 +1,12 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ end_of_line = lf
6
+ indent_size = 4
7
+ indent_style = space
8
+ insert_final_newline = true
9
+ trim_trailing_whitespace = true
10
+
11
+ [*.json]
12
+ indent_size = 2
package/.eslintrc.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "@k03mad"
3
+ }
@@ -0,0 +1,10 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "npm"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "monthly"
7
+ - package-ecosystem: "github-actions"
8
+ directory: "/"
9
+ schedule:
10
+ interval: "daily"
@@ -0,0 +1,40 @@
1
+ name: ESLint
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - master
10
+ schedule:
11
+ - cron: '00 15 * * 6'
12
+
13
+ jobs:
14
+ eslint:
15
+ name: ESLint
16
+ permissions:
17
+ contents: read
18
+ security-events: write
19
+ runs-on: ubuntu-latest
20
+ steps:
21
+ - name: Checkout
22
+ uses: actions/checkout@v4
23
+
24
+ - name: Install NodeJS
25
+ uses: actions/setup-node@v3
26
+ with:
27
+ node-version-file: '.nvmrc'
28
+
29
+ - name: Install dependencies
30
+ run: npm run setup
31
+
32
+ - name: Run ESLint
33
+ run: npm run lint:github
34
+ continue-on-error: true
35
+
36
+ - name: Upload results
37
+ uses: github/codeql-action/upload-sarif@v2
38
+ with:
39
+ sarif_file: eslint-results.sarif
40
+ wait-for-processing: true
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env sh
2
+ . "$(dirname -- "$0")/_/husky.sh"
3
+
4
+ npm run lint
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ 20
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Kirill Molchanov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # DNS leak test
2
+
3
+ Based on [ipleak.net](https://ipleak.net/)
@@ -0,0 +1,89 @@
1
+ import {request, requestCache} from '@k03mad/request';
2
+ import {customAlphabet} from 'nanoid';
3
+ import {lowercase, numbers} from 'nanoid-dictionary';
4
+
5
+ /** */
6
+ export default class IPLeak {
7
+
8
+ /**
9
+ * @param {number} [ipRequestsRps]
10
+ * @param {number} [ipRequestsCacheExpireMs]
11
+ * @param {number} [dnsRequestsCount]
12
+ * @param {number} [dnsRequestsRps]
13
+ * @param {number} [dnsSessionStringLength]
14
+ * @param {number} [dnsUniqStringLength]
15
+ */
16
+ constructor(
17
+ ipRequestsRps = 2,
18
+ ipRequestsCacheExpireMs = 3_600_000,
19
+ dnsRequestsCount = 30,
20
+ dnsRequestsRps = 2,
21
+ dnsSessionStringLength = 40,
22
+ dnsUniqStringLength = 20,
23
+ ) {
24
+ this._ipRequestsRps = ipRequestsRps;
25
+ this._ipRequestsCacheExpireMs = ipRequestsCacheExpireMs;
26
+ this._dnsRequestsCount = dnsRequestsCount;
27
+ this._dnsRequestsRps = dnsRequestsRps;
28
+ this._dnsUniqStringLength = dnsUniqStringLength;
29
+ this._dnsSessionStringLength = dnsSessionStringLength;
30
+ }
31
+
32
+ /** */
33
+ get _endpoints() {
34
+ return {
35
+ info: (ip = '') => `https://ipleak.net/json/${ip}`,
36
+ dns: (session, uniq) => `https://${session}-${uniq}.ipleak.net/dnsdetection/`,
37
+ };
38
+ }
39
+
40
+ /** */
41
+ get _dnsSessionString() {
42
+ return customAlphabet(lowercase + numbers, this._dnsSessionStringLength)();
43
+ }
44
+
45
+ /** */
46
+ get _dnsUniqString() {
47
+ return customAlphabet(lowercase + numbers, this._dnsUniqStringLength)();
48
+ }
49
+
50
+ /**
51
+ * @param {string} ip
52
+ * @returns {Promise<object>}
53
+ */
54
+ async getIpInfo(ip) {
55
+ const ipEndpoint = this._endpoints.info(ip);
56
+
57
+ const {body} = await requestCache(ipEndpoint, {}, {
58
+ expire: this._ipRequestsCacheExpireMs,
59
+ rps: this._ipRequestsRps,
60
+ });
61
+
62
+ return body;
63
+ }
64
+
65
+ /**
66
+ * @param {string} [session]
67
+ * @param {string} [uniqString]
68
+ * @returns {Promise<object>}
69
+ */
70
+ async getDnsInfoOnce(session = this._dnsSessionString, uniqString = this._dnsUniqString) {
71
+ const dnsEndpoint = this._endpoints.dns(session, uniqString);
72
+
73
+ const {body} = await request(dnsEndpoint, {}, {queueBy: session, rps: this._dnsRequestsRps});
74
+ return body;
75
+ }
76
+
77
+ /**
78
+ * @param {string} [session]
79
+ * @returns {Promise<object>}
80
+ */
81
+ async getDnsInfoMulti(session = this._dnsSessionString) {
82
+ const arrayFromLen = Array.from({length: this._dnsRequestsCount});
83
+ await Promise.all(arrayFromLen.map(() => this.getDnsInfoOnce(session)));
84
+
85
+ const info = await this.getDnsInfoOnce(session);
86
+ return info;
87
+ }
88
+
89
+ }
@@ -0,0 +1,47 @@
1
+ /* eslint-disable camelcase */
2
+
3
+ import chalk from 'chalk';
4
+ import clm from 'country-locale-map';
5
+
6
+ const {blue, green} = chalk;
7
+
8
+ /**
9
+ * @param {object} [ipInfo]
10
+ * @param {string} [ipInfo.city_name]
11
+ * @param {string} [ipInfo.country_code]
12
+ * @param {string} [ipInfo.country_name]
13
+ * @param {string} [ipInfo.ip]
14
+ * @param {string} [ipInfo.isp_name]
15
+ * @param {string} [ipInfo.region_name]
16
+ */
17
+ export const formatIpInfo = ({city_name, country_code, country_name, ip, isp_name, region_name}) => {
18
+ let output = '';
19
+
20
+ if (ip) {
21
+ output += `${blue(ip)} `;
22
+ }
23
+
24
+ if (isp_name) {
25
+ output += green(isp_name);
26
+ }
27
+
28
+ output += '\n';
29
+
30
+ if (country_code) {
31
+ const {emoji} = clm.getCountryByAlpha2(country_code);
32
+
33
+ if (emoji) {
34
+ output += `${emoji} `;
35
+ }
36
+ }
37
+
38
+ output += [
39
+ ...new Set([
40
+ country_name,
41
+ region_name,
42
+ city_name,
43
+ ]),
44
+ ].filter(Boolean).join(' :: ');
45
+
46
+ return output;
47
+ };
@@ -0,0 +1,14 @@
1
+ import chalk from 'chalk';
2
+
3
+ const {bgBlackBright, magenta} = chalk;
4
+
5
+ /**
6
+ * @param {any} msg
7
+ */
8
+ // 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`);
package/app/index.js ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+
3
+ import IPLeak from './api/IPLeak.js';
4
+ import {formatIpInfo} from './helpers/ip.js';
5
+ import {log, logHeader} from './helpers/log.js';
6
+
7
+ const api = new IPLeak();
8
+
9
+ const currentIpInfo = await api.getIpInfo();
10
+
11
+ logHeader('IP');
12
+ log(formatIpInfo(currentIpInfo));
13
+
14
+ const dnsInfo = await api.getDnsInfoMulti();
15
+ const dnsIps = [...new Set(Object.keys(dnsInfo.ip))];
16
+
17
+ logHeader('DNS');
18
+
19
+ const dnsData = await Promise.all(dnsIps.map(ip => api.getIpInfo(ip)));
20
+
21
+ dnsData
22
+ .sort((a, b) => a?.ip?.localeCompare(b?.ip))
23
+ .forEach(data => log(formatIpInfo(data), '\n'));
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@k03mad/dns-leak",
3
+ "version": "1.0.0",
4
+ "description": "DNS leak test",
5
+ "maintainers": [
6
+ "Kirill Molchanov <k03.mad@gmail.com"
7
+ ],
8
+ "main": "app/api/IPLeak.js",
9
+ "bin": "app/index.js",
10
+ "repository": "k03mad/dns-leak",
11
+ "license": "MIT",
12
+ "type": "module",
13
+ "engines": {
14
+ "node": ">=20"
15
+ },
16
+ "dependencies": {
17
+ "@k03mad/request": "3.2.0",
18
+ "chalk": "5.3.0",
19
+ "country-locale-map": "1.8.15",
20
+ "nanoid": "5.0.2",
21
+ "nanoid-dictionary": "5.0.0-beta.1"
22
+ },
23
+ "devDependencies": {
24
+ "@k03mad/eslint-config": "13.3.1",
25
+ "@microsoft/eslint-formatter-sarif": "3.0.0",
26
+ "eslint": "8.53.0",
27
+ "eslint-plugin-import": "2.29.0",
28
+ "eslint-plugin-jsdoc": "46.8.2",
29
+ "eslint-plugin-n": "16.2.0",
30
+ "eslint-plugin-simple-import-sort": "10.0.0",
31
+ "eslint-plugin-sort-destructure-keys": "1.5.0",
32
+ "eslint-plugin-unicorn": "49.0.0",
33
+ "husky": "8.0.3"
34
+ },
35
+ "scripts": {
36
+ "lint": "eslint ./ --report-unused-disable-directives",
37
+ "lint:github": "eslint ./ --format @microsoft/eslint-formatter-sarif --output-file eslint-results.sarif",
38
+ "clean": "rm -rfv ./node_modules || true",
39
+ "setup": "npm run clean && npm i",
40
+ "prepare": "husky install"
41
+ }
42
+ }