@k03mad/dns-leak 5.0.0 → 6.0.1

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 Kirill Molchanov
3
+ Copyright (c) Kirill Molchanov
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,30 +1,17 @@
1
- # DNS leak test
1
+ # DNS-leak test
2
+
3
+ ## Using API/tools
2
4
 
3
- Using API/tools:\
4
5
  — [ipleak.net](https://airvpn.org/forums/topic/14737-api)\
5
6
  — [ipwhois.io](https://ipwhois.io/documentation)\
6
7
  — [cloudping.cloud](https://www.cloudping.cloud/cdn)\
7
8
  — [nextdns.io](https://test.nextdns.io)\
8
9
  — [wander.science](https://wander.science/projects/dns/dnssec-resolver-test)
9
10
 
10
- ## Global
11
+ ## Use
11
12
 
12
13
  ```bash
13
14
  npm i @k03mad/dns-leak -g
14
- ```
15
15
 
16
- ```bash
17
16
  dns-leak
18
17
  ```
19
-
20
- ## API
21
-
22
- ```bash
23
- npm i @k03mad/dns-leak
24
- ```
25
-
26
- ```js
27
- import {CloudPing, IPLeak, IPWhois, NextDNS} from '@k03mad/dns-leak';
28
- ```
29
-
30
- Details at [./app/api](/app/api) folder
package/app/api/_index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  export {default as CloudPing} from './cloud-ping.js';
2
2
  export {default as IPLeak} from './ip-leak.js';
3
- export {default as IPWhois} from './ip-whois.js';
4
3
  export {default as NextDNS} from './next-dns.js';
5
4
  export {default as Wander} from './wander.js';
@@ -22,7 +22,7 @@ export const info = msg => gray(msg);
22
22
  /**
23
23
  * @param {string} msg
24
24
  */
25
- export const org = msg => green(msg);
25
+ export const orgIsp = msg => green(msg);
26
26
 
27
27
  /**
28
28
  * @param {string} msg
@@ -31,19 +31,23 @@ export const address = msg => blue(msg);
31
31
 
32
32
  /**
33
33
  * @param {object} [ipInfo]
34
- * @param {object} [ipInfo.connection]
35
- * @param {object} [ipInfo.flag]
36
34
  * @param {string} [ipInfo.city]
37
35
  * @param {string} [ipInfo.country]
36
+ * @param {string} [ipInfo.emoji]
38
37
  * @param {string} [ipInfo.ip]
38
+ * @param {string} [ipInfo.isp]
39
+ * @param {string} [ipInfo.ispDomain]
40
+ * @param {string} [ipInfo.org]
39
41
  * @param {string} [ipInfo.region]
40
42
  */
41
43
  export const formatIpInfo = ({
42
44
  city,
43
- connection,
44
45
  country,
45
- flag,
46
+ emoji,
46
47
  ip,
48
+ isp,
49
+ ispDomain,
50
+ org,
47
51
  region,
48
52
  } = {}) => {
49
53
  let output = '';
@@ -52,26 +56,26 @@ export const formatIpInfo = ({
52
56
  output += `${address(ip)}\n`;
53
57
  }
54
58
 
55
- if (connection?.org) {
56
- output += `${org(connection.org)} `;
59
+ if (org) {
60
+ output += `${orgIsp(org)} `;
57
61
  }
58
62
 
59
- if (connection?.isp && !connection?.org?.includes(connection?.isp)) {
60
- if (connection?.org) {
61
- output += org('/ ');
63
+ if (isp && !org?.includes(isp)) {
64
+ if (org) {
65
+ output += orgIsp('/ ');
62
66
  }
63
67
 
64
- output += `${org(connection.isp)} `;
68
+ output += `${orgIsp(isp)} `;
65
69
  }
66
70
 
67
- if (connection?.domain) {
68
- output += info(`(${connection.domain})`);
71
+ if (ispDomain) {
72
+ output += info(`(${ispDomain})`);
69
73
  }
70
74
 
71
75
  output += '\n';
72
76
 
73
- if (flag?.emoji) {
74
- output += `${flag.emoji} `;
77
+ if (emoji) {
78
+ output += `${emoji} `;
75
79
  }
76
80
 
77
81
  output += [
@@ -95,7 +99,7 @@ export const formatLocationInfo = ({city, country, iata}) => {
95
99
  let output = '';
96
100
 
97
101
  if (iata) {
98
- output += `${org(iata)}\n`;
102
+ output += `${orgIsp(iata)}\n`;
99
103
  }
100
104
 
101
105
  if (country) {
package/app/run.js CHANGED
@@ -1,20 +1,21 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import {CloudPing, IPLeak, IPWhois, NextDNS, Wander} from './api/_index.js';
4
- import {log} from './helpers/log.js';
3
+ import {ip2geo} from '@k03mad/ip2geo';
4
+ import {log} from '@k03mad/simple-log';
5
+
6
+ import {CloudPing, IPLeak, NextDNS, Wander} from './api/_index.js';
5
7
  import * as spinner from './helpers/spinner.js';
6
8
  import {formatIpInfo, formatLocationInfo, header} from './helpers/text.js';
7
9
 
8
10
  const LeakApi = new IPLeak();
9
11
  const NextApi = new NextDNS();
10
- const WhoisApi = new IPWhois();
11
12
  const CloudPingApi = new CloudPing();
12
13
  const WanderApi = new Wander();
13
14
 
14
- const [leak, next, whois, location, dnssec] = await Promise.allSettled([
15
+ const [leak, next, geoip, location, dnssec] = await Promise.allSettled([
15
16
  LeakApi.getDnsInfoMulti({isSpinnerEnabled: true}),
16
17
  NextApi.getTest(),
17
- WhoisApi.getIpInfo(),
18
+ ip2geo(),
18
19
  CloudPingApi.getCurrentLocation(),
19
20
  WanderApi.checkDNSSEC(),
20
21
  ]);
@@ -31,7 +32,7 @@ const dnsIps = [
31
32
 
32
33
  const dnsIpsInfo = await Promise.all(dnsIps.map(async ip => {
33
34
  try {
34
- const data = await WhoisApi.getIpInfo({ip});
35
+ const data = await ip2geo(ip);
35
36
  spinner.count(spinnerName, dnsIps.length);
36
37
  return data;
37
38
  } catch {}
@@ -44,10 +45,10 @@ const dnsIpsInfoFormatted = dnsIpsInfo
44
45
 
45
46
  const output = [];
46
47
 
47
- if (whois.value) {
48
+ if (geoip.value) {
48
49
  output.push(
49
50
  header('IP'),
50
- formatIpInfo(whois.value),
51
+ formatIpInfo(geoip.value),
51
52
  );
52
53
  }
53
54
 
@@ -60,7 +61,7 @@ if (dnsIpsInfoFormatted.length > 0) {
60
61
 
61
62
  if (next.value?.ecs) {
62
63
  try {
63
- const data = await WhoisApi.getIpInfo({ip: next.value.ecs.replace(/\/.+/, '')});
64
+ const data = await ip2geo(next.value.ecs.replace(/\/.+/, ''));
64
65
  data.ip += ` (${next.value.ecs})`;
65
66
 
66
67
  output.push(
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@k03mad/dns-leak",
3
- "version": "5.0.0",
3
+ "version": "6.0.1",
4
4
  "description": "DNS leak test",
5
5
  "maintainers": [
6
6
  "Kirill Molchanov <k03.mad@gmail.com"
7
7
  ],
8
- "main": "app/api/_index.js",
9
8
  "bin": {
10
9
  "dns-leak": "app/run.js"
11
10
  },
@@ -19,7 +18,9 @@
19
18
  "node": ">=20"
20
19
  },
21
20
  "dependencies": {
21
+ "@k03mad/ip2geo": "2.3.1",
22
22
  "@k03mad/request": "5.4.1",
23
+ "@k03mad/simple-log": "2.0.0",
23
24
  "chalk": "5.3.0",
24
25
  "country-locale-map": "1.9.0",
25
26
  "nanoid": "5.0.4",
@@ -27,7 +28,7 @@
27
28
  "ora": "8.0.1"
28
29
  },
29
30
  "devDependencies": {
30
- "@k03mad/eslint-config": "18.1.0",
31
+ "@k03mad/eslint-config": "19.3.0",
31
32
  "eslint": "8.56.0",
32
33
  "husky": "8.0.3"
33
34
  },
@@ -1,44 +0,0 @@
1
- import {requestCache} from '@k03mad/request';
2
-
3
- /** */
4
- export default class IPWhois {
5
-
6
- /**
7
- * @param {object} [opts]
8
- * @param {number} [opts.ipRequestsCacheExpireSec] ip info requests cache ttl ms for same ip
9
- * @param {number} [opts.requestsRps] parallel requests rps
10
- */
11
- constructor({
12
- ipRequestsCacheExpireSec = 3600,
13
- requestsRps = 2,
14
- } = {}) {
15
- this._ipRequestsCacheExpireSec = ipRequestsCacheExpireSec;
16
- this._requestsRps = requestsRps;
17
- }
18
-
19
- /** */
20
- static get endpoints() {
21
- return {
22
-
23
- /** @param {string} ip */
24
- ip: ip => `https://ipwho.is/${ip}`,
25
- };
26
- }
27
-
28
- /**
29
- * @param {object} [opts]
30
- * @param {string} [opts.ip]
31
- * @returns {Promise<object>}
32
- */
33
- async getIpInfo({ip = ''} = {}) {
34
- const ipEndpoint = IPWhois.endpoints.ip(ip);
35
-
36
- const {body} = await requestCache(ipEndpoint, {}, {
37
- expire: this._ipRequestsCacheExpireSec,
38
- rps: this._requestsRps,
39
- });
40
-
41
- return body;
42
- }
43
-
44
- }
@@ -1,5 +0,0 @@
1
- /**
2
- * @param {any} msg
3
- */
4
- // eslint-disable-next-line no-console
5
- export const log = msg => console.log(msg);