Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
2a1fbeb183 | |||
a6a47d2e96 | |||
84ad6bbcd6 | |||
4102c3a692 | |||
6281ab0c80 | |||
622c65291e | |||
dd8c97b99a | |||
9c56dc51e3 | |||
45cbd3a953 | |||
d3e2655212 | |||
e02b2253f5 | |||
862577745d | |||
ca72206ab4 | |||
0221c3207e | |||
f2b8fa57af | |||
e5b072d99b | |||
97c57b2865 | |||
e04485231d |
@ -12,40 +12,36 @@ stages:
|
|||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- pnpm install -g pnpm
|
||||||
|
- pnpm install -g @shipzone/npmci
|
||||||
|
- npmci npm prepare
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# security stage
|
||||||
|
# ====================
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
mirror:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
auditProductionDependencies:
|
auditProductionDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command npm install --production --ignore-scripts
|
- npmci command pnpm audit --audit-level=high --prod
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
- npmci command npm audit --audit-level=high --only=prod --production
|
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
auditDevDependencies:
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
|
||||||
- npmci command npm install --ignore-scripts
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command npm audit --audit-level=high --only=dev
|
- npmci command pnpm audit --audit-level=high --dev
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
|
||||||
@ -56,7 +52,6 @@ auditDevDependencies:
|
|||||||
testStable:
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
@ -67,10 +62,9 @@ testStable:
|
|||||||
testBuild:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command npm run build
|
- npmci npm build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
@ -96,10 +90,9 @@ codequality:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g typescript
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
@ -119,11 +112,9 @@ trigger:
|
|||||||
pages:
|
pages:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command npm run buildDocs
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${relativeFile}"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "test.ts",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"args": [
|
|
||||||
"test/test.ts"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
"gitrepo": "smartdns",
|
"gitrepo": "smartdns",
|
||||||
"shortDescription": "smart dns methods written in TypeScript",
|
"description": "smart dns methods written in TypeScript",
|
||||||
"npmPackagename": "@pushrocks/smartdns",
|
"npmPackagename": "@pushrocks/smartdns",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
11169
package-lock.json
generated
11169
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
29
package.json
29
package.json
@ -1,13 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartdns",
|
"name": "@pushrocks/smartdns",
|
||||||
"version": "4.0.7",
|
"version": "5.0.4",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "smart dns methods written in TypeScript",
|
"description": "smart dns methods written in TypeScript",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild --web)"
|
"build": "(tsbuild --web --allowimplicitany)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -25,18 +26,19 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/dnsly#README",
|
"homepage": "https://gitlab.com/pushrocks/dnsly#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.10",
|
"@pushrocks/smartdelay": "^2.0.13",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/smartenv": "^5.0.2",
|
||||||
"@pushrocks/smartrequest": "^1.1.47",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
"@tsclass/tsclass": "^3.0.21"
|
"@pushrocks/smartrequest": "^2.0.11",
|
||||||
|
"@tsclass/tsclass": "^4.0.17",
|
||||||
|
"dns2": "^2.0.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.24",
|
"@gitzone/tsbuild": "^2.1.63",
|
||||||
"@gitzone/tstest": "^1.0.43",
|
"@gitzone/tsrun": "^1.2.39",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@gitzone/tstest": "^1.0.72",
|
||||||
"@types/node": "^14.0.27",
|
"@pushrocks/tapbundle": "^5.0.4",
|
||||||
"tslint": "^6.1.3",
|
"@types/node": "^18.15.11"
|
||||||
"tslint-config-prettier": "^1.18.0"
|
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
@ -52,5 +54,6 @@
|
|||||||
],
|
],
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
]
|
],
|
||||||
|
"type": "module"
|
||||||
}
|
}
|
||||||
|
4462
pnpm-lock.yaml
generated
Normal file
4462
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -21,7 +21,6 @@ Code Style | [](htt
|
|||||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -47,7 +46,6 @@ We are always happy for code contributions. If you are not the code contributing
|
|||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
## Legal
|
||||||
|
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
|
||||||
|
33
test/test.ts
33
test/test.ts
@ -1,16 +1,16 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
|
|
||||||
import * as smartdns from '../ts/index';
|
import * as smartdns from '../ts/index.js';
|
||||||
|
|
||||||
let testDnsly: smartdns.Smartdns;
|
let testDnsly: smartdns.Smartdns;
|
||||||
|
|
||||||
tap.test('should create an instance of Dnsly', async () => {
|
tap.test('should create an instance of Dnsly', async () => {
|
||||||
testDnsly = new smartdns.Smartdns({});
|
testDnsly = new smartdns.Smartdns({});
|
||||||
expect(testDnsly).to.be.instanceOf(smartdns.Smartdns);
|
expect(testDnsly).toBeInstanceOf(smartdns.Smartdns);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should get an A DNS Record', async () => {
|
tap.test('should get an A DNS Record', async () => {
|
||||||
return expect(testDnsly.getRecordA('dnsly_a.bleu.de')).to.eventually.deep.equal([
|
return expect(await testDnsly.getRecordsA('dnsly_a.bleu.de')).toEqual([
|
||||||
{
|
{
|
||||||
name: 'dnsly_a.bleu.de',
|
name: 'dnsly_a.bleu.de',
|
||||||
value: '127.0.0.1',
|
value: '127.0.0.1',
|
||||||
@ -21,7 +21,7 @@ tap.test('should get an A DNS Record', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should get an AAAA Record', async () => {
|
tap.test('should get an AAAA Record', async () => {
|
||||||
return expect(testDnsly.getRecordAAAA('dnsly_aaaa.bleu.de')).to.eventually.deep.equal([
|
return expect(await testDnsly.getRecordsAAAA('dnsly_aaaa.bleu.de')).toEqual([
|
||||||
{
|
{
|
||||||
name: 'dnsly_aaaa.bleu.de',
|
name: 'dnsly_aaaa.bleu.de',
|
||||||
value: '::1',
|
value: '::1',
|
||||||
@ -32,7 +32,7 @@ tap.test('should get an AAAA Record', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should get a txt record', async () => {
|
tap.test('should get a txt record', async () => {
|
||||||
return expect(testDnsly.getRecordTxt('dnsly_txt.bleu.de')).to.eventually.deep.equal([
|
return expect(await testDnsly.getRecordsTxt('dnsly_txt.bleu.de')).toEqual([
|
||||||
{
|
{
|
||||||
name: 'dnsly_txt.bleu.de',
|
name: 'dnsly_txt.bleu.de',
|
||||||
value: 'sometext_txt',
|
value: 'sometext_txt',
|
||||||
@ -43,34 +43,37 @@ tap.test('should get a txt record', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should, get a mx record for a domain', async () => {
|
tap.test('should, get a mx record for a domain', async () => {
|
||||||
const res = await testDnsly.getRecord('bleu.de', 'MX');
|
const res = await testDnsly.getRecords('bleu.de', 'MX');
|
||||||
console.log(res);
|
console.log(res);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should check until DNS is available', async () => {
|
tap.test('should check until DNS is available', async () => {
|
||||||
return expect(testDnsly.checkUntilAvailable('dnsly_txt.bleu.de', 'TXT', 'sometext_txt')).to
|
return expect(
|
||||||
.eventually.be.true;
|
await testDnsly.checkUntilAvailable('dnsly_txt.bleu.de', 'TXT', 'sometext_txt')
|
||||||
|
).toBeTrue();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should check until DNS is available an return false if it fails', async () => {
|
tap.test('should check until DNS is available an return false if it fails', async () => {
|
||||||
return expect(testDnsly.checkUntilAvailable('dnsly_txt.bleu.de', 'TXT', 'sometext_txt2')).to
|
return expect(
|
||||||
.eventually.be.false;
|
await testDnsly.checkUntilAvailable('dnsly_txt.bleu.de', 'TXT', 'sometext_txt2')
|
||||||
|
).toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should check until DNS is available an return false if it fails', async () => {
|
tap.test('should check until DNS is available an return false if it fails', async () => {
|
||||||
return expect(testDnsly.checkUntilAvailable('dnsly_txtNotThere.bleu.de', 'TXT', 'sometext_txt2'))
|
return expect(
|
||||||
.to.eventually.be.false;
|
await testDnsly.checkUntilAvailable('dnsly_txtNotThere.bleu.de', 'TXT', 'sometext_txt2')
|
||||||
|
).toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should get name server for hostname', async () => {
|
tap.test('should get name server for hostname', async () => {
|
||||||
let result = await testDnsly.getNameServer('bleu.de');
|
let result = await testDnsly.getNameServers('bleu.de');
|
||||||
console.log(result);
|
console.log(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should detect dns sec', async () => {
|
tap.test('should detect dns sec', async () => {
|
||||||
const result = await testDnsly.getRecordA('lossless.com');
|
const result = await testDnsly.getRecordsA('lossless.com');
|
||||||
console.log(result[0]);
|
console.log(result[0]);
|
||||||
expect(result[0].dnsSecEnabled).to.be.true;
|
expect(result[0].dnsSecEnabled).toBeTrue();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@pushrocks/smartdns',
|
||||||
|
version: '5.0.4',
|
||||||
|
description: 'smart dns methods written in TypeScript'
|
||||||
|
}
|
@ -1,5 +1,8 @@
|
|||||||
|
import * as smartenv from '@pushrocks/smartenv';
|
||||||
|
const smartenvInstance = new smartenv.Smartenv();
|
||||||
// node native scope
|
// node native scope
|
||||||
import * as dns from 'dns';
|
import type dnsType from 'dns';
|
||||||
|
const dns: typeof dnsType = await smartenvInstance.getSafeNodeModule('dns');
|
||||||
|
|
||||||
export { dns };
|
export { dns };
|
||||||
|
|
||||||
@ -8,8 +11,12 @@ import * as smartdelay from '@pushrocks/smartdelay';
|
|||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import * as smartrequest from '@pushrocks/smartrequest';
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
|
|
||||||
export { smartdelay, smartpromise, smartrequest };
|
export { smartdelay, smartenv, smartpromise, smartrequest };
|
||||||
|
|
||||||
import * as tsclass from '@tsclass/tsclass';
|
import * as tsclass from '@tsclass/tsclass';
|
||||||
|
|
||||||
export { tsclass };
|
export { tsclass };
|
||||||
|
|
||||||
|
// third party scope
|
||||||
|
const dns2 = smartenvInstance.getSafeNodeModule('dns2');
|
||||||
|
export { dns2 };
|
||||||
|
98
ts/index.ts
98
ts/index.ts
@ -1,7 +1,27 @@
|
|||||||
import * as plugins from './dnsly.plugins';
|
import * as plugins from './dnsly.plugins.js';
|
||||||
|
|
||||||
export type TDnsProvider = 'google' | 'cloudflare';
|
export type TDnsProvider = 'google' | 'cloudflare';
|
||||||
|
|
||||||
|
export const makeNodeProcessUseDnsProvider = (providerArg: TDnsProvider) => {
|
||||||
|
switch (providerArg) {
|
||||||
|
case 'cloudflare':
|
||||||
|
plugins.dns.setServers([
|
||||||
|
'1.1.1.1',
|
||||||
|
'1.0.0.1',
|
||||||
|
'[2606:4700:4700::1111]',
|
||||||
|
'[2606:4700:4700::1001]',
|
||||||
|
]);
|
||||||
|
break;
|
||||||
|
case 'google':
|
||||||
|
plugins.dns.setServers([
|
||||||
|
'8.8.8.8',
|
||||||
|
'8.8.4.4',
|
||||||
|
'[2001:4860:4860::8888]',
|
||||||
|
'[2606:4700:4700::1001]',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export interface ISmartDnsConstructorOptions {}
|
export interface ISmartDnsConstructorOptions {}
|
||||||
|
|
||||||
export interface IGoogleDNSHTTPSResponse {
|
export interface IGoogleDNSHTTPSResponse {
|
||||||
@ -56,7 +76,12 @@ export class Smartdns {
|
|||||||
if (runCycles < cyclesArg) {
|
if (runCycles < cyclesArg) {
|
||||||
runCycles++;
|
runCycles++;
|
||||||
try {
|
try {
|
||||||
const myRecordArray = await this.getRecordWithNodeDNS(recordNameArg, recordTypeArg);
|
let myRecordArray: plugins.tsclass.network.IDnsRecord[];
|
||||||
|
if (runCycles % 2 === 0 || !plugins.dns) {
|
||||||
|
myRecordArray = await this.getRecords(recordNameArg, recordTypeArg, 0);
|
||||||
|
} else {
|
||||||
|
myRecordArray = await this.getRecordWithNodeDNS(recordNameArg, recordTypeArg);
|
||||||
|
}
|
||||||
const myRecord = myRecordArray[0].value;
|
const myRecord = myRecordArray[0].value;
|
||||||
if (myRecord === expectedValue) {
|
if (myRecord === expectedValue) {
|
||||||
console.log(
|
console.log(
|
||||||
@ -68,6 +93,7 @@ export class Smartdns {
|
|||||||
return await doCheck();
|
return await doCheck();
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
// console.log(err);
|
||||||
await plugins.smartdelay.delayFor(intervalArg);
|
await plugins.smartdelay.delayFor(intervalArg);
|
||||||
return await doCheck();
|
return await doCheck();
|
||||||
}
|
}
|
||||||
@ -84,37 +110,50 @@ export class Smartdns {
|
|||||||
/**
|
/**
|
||||||
* get A Dns Record
|
* get A Dns Record
|
||||||
*/
|
*/
|
||||||
public async getRecordA(recordNameArg: string): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
public async getRecordsA(recordNameArg: string): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
||||||
return await this.getRecord(recordNameArg, 'A');
|
return await this.getRecords(recordNameArg, 'A');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get AAAA Record
|
* get AAAA Record
|
||||||
*/
|
*/
|
||||||
public async getRecordAAAA(recordNameArg: string) {
|
public async getRecordsAAAA(recordNameArg: string) {
|
||||||
return await this.getRecord(recordNameArg, 'AAAA');
|
return await this.getRecords(recordNameArg, 'AAAA');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gets a txt record
|
* gets a txt record
|
||||||
*/
|
*/
|
||||||
public async getRecordTxt(recordNameArg: string): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
public async getRecordsTxt(recordNameArg: string): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
||||||
return await this.getRecord(recordNameArg, 'TXT');
|
return await this.getRecords(recordNameArg, 'TXT');
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getRecord(
|
public async getRecords(
|
||||||
recordNameArg: string,
|
recordNameArg: string,
|
||||||
recordTypeArg: plugins.tsclass.network.TDnsRecordType
|
recordTypeArg: plugins.tsclass.network.TDnsRecordType,
|
||||||
|
retriesCounterArg = 20
|
||||||
): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
||||||
const requestUrl = `https://cloudflare-dns.com/dns-query?name=${recordNameArg}&type=${recordTypeArg}&do=1`;
|
const requestUrl = `https://cloudflare-dns.com/dns-query?name=${recordNameArg}&type=${recordTypeArg}&do=1`;
|
||||||
const response = await plugins.smartrequest.request(requestUrl, {
|
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
accept: 'application/dns-json',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const returnArray: plugins.tsclass.network.IDnsRecord[] = [];
|
const returnArray: plugins.tsclass.network.IDnsRecord[] = [];
|
||||||
const responseBody: IGoogleDNSHTTPSResponse = response.body;
|
const getResponseBody = async (counterArg = 0): Promise<IGoogleDNSHTTPSResponse> => {
|
||||||
|
const response = await plugins.smartrequest.request(requestUrl, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
accept: 'application/dns-json',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const responseBody: IGoogleDNSHTTPSResponse = response.body;
|
||||||
|
if (responseBody?.Status !== 0 && counterArg < retriesCounterArg) {
|
||||||
|
await plugins.smartdelay.delayFor(500);
|
||||||
|
return getResponseBody(counterArg++);
|
||||||
|
} else {
|
||||||
|
return responseBody;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const responseBody = await getResponseBody();
|
||||||
|
if (!responseBody.Answer || !typeof responseBody.Answer[Symbol.iterator]) {
|
||||||
|
return returnArray;
|
||||||
|
}
|
||||||
for (const dnsEntry of responseBody.Answer) {
|
for (const dnsEntry of responseBody.Answer) {
|
||||||
if (dnsEntry.data.startsWith('"') && dnsEntry.data.endsWith('"')) {
|
if (dnsEntry.data.startsWith('"') && dnsEntry.data.endsWith('"')) {
|
||||||
dnsEntry.data = dnsEntry.data.replace(/^"(.*)"$/, '$1');
|
dnsEntry.data = dnsEntry.data.replace(/^"(.*)"$/, '$1');
|
||||||
@ -140,7 +179,6 @@ export class Smartdns {
|
|||||||
recordNameArg: string,
|
recordNameArg: string,
|
||||||
recordTypeArg: plugins.tsclass.network.TDnsRecordType
|
recordTypeArg: plugins.tsclass.network.TDnsRecordType
|
||||||
): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
||||||
this.setNodeDnsProvider('cloudflare');
|
|
||||||
const done = plugins.smartpromise.defer<plugins.tsclass.network.IDnsRecord[]>();
|
const done = plugins.smartpromise.defer<plugins.tsclass.network.IDnsRecord[]>();
|
||||||
plugins.dns.resolve(recordNameArg, recordTypeArg, (err, recordsArg) => {
|
plugins.dns.resolve(recordNameArg, recordTypeArg, (err, recordsArg) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -161,7 +199,7 @@ export class Smartdns {
|
|||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getNameServer(domainNameArg: string): Promise<string[]> {
|
public async getNameServers(domainNameArg: string): Promise<string[]> {
|
||||||
const done = plugins.smartpromise.defer<string[]>();
|
const done = plugins.smartpromise.defer<string[]>();
|
||||||
plugins.dns.resolveNs(domainNameArg, (err, result) => {
|
plugins.dns.resolveNs(domainNameArg, (err, result) => {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
@ -174,28 +212,6 @@ export class Smartdns {
|
|||||||
return await done.promise;
|
return await done.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* set the DNS provider
|
|
||||||
*/
|
|
||||||
public setNodeDnsProvider(dnsProvider: TDnsProvider) {
|
|
||||||
if (!this.dnsServerIp) {
|
|
||||||
console.log(
|
|
||||||
`Warning: Setting the nodejs dns authority to ${dnsProvider}. Only do this if you know what you are doing.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (dnsProvider === 'google' && this.dnsServerIp !== '8.8.8.8') {
|
|
||||||
this.dnsServerIp = '8.8.8.8';
|
|
||||||
this.dnsServerPort = 53;
|
|
||||||
plugins.dns.setServers(['8.8.8.8', '8.8.4.4']);
|
|
||||||
} else if (dnsProvider === 'cloudflare' && this.dnsServerIp !== '1.1.1.1') {
|
|
||||||
this.dnsServerIp = '1.1.1.1';
|
|
||||||
this.dnsServerPort = 53;
|
|
||||||
plugins.dns.setServers(['1.1.1.1', '1.0.0.1']);
|
|
||||||
} else {
|
|
||||||
throw new Error('unknown dns provider');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public convertDnsTypeNameToTypeNumber(dnsTypeNameArg: string): number {
|
public convertDnsTypeNameToTypeNumber(dnsTypeNameArg: string): number {
|
||||||
return this.dnsTypeMap[dnsTypeNameArg];
|
return this.dnsTypeMap[dnsTypeNameArg];
|
||||||
}
|
}
|
||||||
|
10
tsconfig.json
Normal file
10
tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext",
|
||||||
|
"esModuleInterop": true
|
||||||
|
}
|
||||||
|
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
Reference in New Issue
Block a user