Skip to content

Commit

Permalink
feat: add arg dns server
Browse files Browse the repository at this point in the history
  • Loading branch information
iugo committed Feb 27, 2023
1 parent 6626906 commit bcf050d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"editor.formatOnSave": true,
"[sql]": {
"editor.formatOnSave": false
},
"[json]": {
"editor.defaultFormatter": "denoland.vscode-deno"
}
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ OPTIONS:
-d, --domain
Set domain

--dns
Set DNS server.

-t, --token
Set he.net auth token

Expand Down
1 change: 1 addition & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"compilerOptions": {
"strict": true
},
"lock": false,
"lint": {
"files": {
"include": [
Expand Down
4 changes: 3 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const args = parse<
{
d: string;
domain: string;
dns: string;
t: string;
token: string;
delaytime: number;
Expand Down Expand Up @@ -45,6 +46,7 @@ const timeout = args.timeout ?? 5000;
const delay = Number(
args.delaytime ?? Deno.env.get('USEDDNS_DELAY_TIME') ?? 5000,
);
const dnsServer = args.dns;

if (!domain || !token) {
throw new Error(
Expand Down Expand Up @@ -81,7 +83,7 @@ let lastFailInfo = '';
const displayInfoLoopTime = 60000;

setInterval(async () => {
const [err, res] = await checkIP(token, domain, { timeout });
const [err, res] = await checkIP(token, domain, { timeout, dnsServer });
const d = new Date();
if (err) {
failTime += 1;
Expand Down
4 changes: 2 additions & 2 deletions src/useddns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export function getDNSIP(
export async function checkIP(
token: string,
domain: string,
{ timeout }: { timeout?: number } = {},
{ timeout, dnsServer }: { timeout?: number; dnsServer?: string } = {},
): Promise<[err: Error] | [err: null, res: string]> {
try {
const currentIP = await getCurrentIP({ timeout });
const DNSIP = await getDNSIP(domain, { timeout });
const DNSIP = await getDNSIP(domain, { timeout, dns: dnsServer });
if (!currentIP || !DNSIP) {
throw new Error(
'Did not get IP: ' + JSON.stringify({ currentIP, DNSIP }),
Expand Down

0 comments on commit bcf050d

Please sign in to comment.