Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance discrepancy: dnsx as library lag compared to CLI #512

Open
iamnihal opened this issue Nov 29, 2023 · 1 comment
Open

Performance discrepancy: dnsx as library lag compared to CLI #512

iamnihal opened this issue Nov 29, 2023 · 1 comment
Labels
Investigation Something to Investigate Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors.

Comments

@iamnihal
Copy link

dnsx version: v1.1.6

Current Behavior:

I'm utilizing dnsx as a library in my program, generating subdomains from alterx, and resolving them through dnsx. The problem arises when I use dnsx as a library; the time it takes to resolve 691 subdomains is 1 minute and 14 seconds. However, when I perform the same operation using the dnsx binary CLI, it takes only 1.75 seconds. As suggested by @dogancanbakir, I've attempted passing default values, but that doesn't seem to resolve the issue.

Expected Behavior:

When used as a library, dnsx should resolve the subdomains in the same time as when used as a CLI utility."

Steps To Reproduce:

I'm using dnsx in my program as below:

package main

import (
	"fmt"
	"time"

	"github.com/projectdiscovery/dnsx/libs/dnsx"
)

func DnsxEnrich(subdomains []string) ([]string, error) {

	var result []string

	dnsClient, err := dnsx.New(dnsx.Options{
		BaseResolvers: []string{
			"udp:1.1.1.1:53",         // Cloudflare
			"udp:1.0.0.1:53",         // Cloudflare
			"udp:8.8.8.8:53",         // Google
			"udp:8.8.4.4:53",         // Google
			"udp:9.9.9.9:53",         // Quad9
			"udp:149.112.112.112:53", // Quad9
			"udp:208.67.222.222:53",  // Open DNS
			"udp:208.67.220.220:53",  // Open DNS
		},
		MaxRetries:        2,
		QuestionTypes:     dnsx.DefaultOptions.QuestionTypes,
		Trace:             false,
		TraceMaxRecursion: dnsx.DefaultOptions.TraceMaxRecursion,
		Hostsfile:         false,
		OutputCDN:         false,
	})
	if err != nil {
		fmt.Printf("err: %v\n", err)
		return []string{}, fmt.Errorf("error creating dnsx client: %v", err)
	}

	timeStart := time.Now()

	for _, subdomain := range subdomains {
		res, _ := dnsClient.Lookup(subdomain)

		if len(res) > 1 {
			result = append(result, subdomain)
		}
	}

	fmt.Println("\nCompleted in", time.Since(timeStart))
	return result, nil
}

When I pass 691 subdomains to the DnsxEnrich function, it takes approximately 1 minute and 14 seconds to resolve all the subdomains. In contrast, using dnsx as the CLI tool completes the process in just 1.75 seconds.

Output:

dnsx as CLI

dnsx CLI

dnsx as library

dnsx library

@iamnihal iamnihal added the Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors. label Nov 29, 2023
@dogancanbakir dogancanbakir self-assigned this Nov 29, 2023
@dogancanbakir dogancanbakir added the Investigation Something to Investigate label Nov 30, 2023
@lordsky
Copy link

lordsky commented Dec 6, 2023

dnsx version: v1.1.6

Current Behavior:

I'm utilizing dnsx as a library in my program, generating subdomains from alterx, and resolving them through dnsx. The problem arises when I use dnsx as a library; the time it takes to resolve 691 subdomains is 1 minute and 14 seconds. However, when I perform the same operation using the dnsx binary CLI, it takes only 1.75 seconds. As suggested by @dogancanbakir, I've attempted passing default values, but that doesn't seem to resolve the issue.

Expected Behavior:

When used as a library, dnsx should resolve the subdomains in the same time as when used as a CLI utility."

Steps To Reproduce:

I'm using dnsx in my program as below:

package main

import (
	"fmt"
	"time"

	"github.com/projectdiscovery/dnsx/libs/dnsx"
)

func DnsxEnrich(subdomains []string) ([]string, error) {

	var result []string

	dnsClient, err := dnsx.New(dnsx.Options{
		BaseResolvers: []string{
			"udp:1.1.1.1:53",         // Cloudflare
			"udp:1.0.0.1:53",         // Cloudflare
			"udp:8.8.8.8:53",         // Google
			"udp:8.8.4.4:53",         // Google
			"udp:9.9.9.9:53",         // Quad9
			"udp:149.112.112.112:53", // Quad9
			"udp:208.67.222.222:53",  // Open DNS
			"udp:208.67.220.220:53",  // Open DNS
		},
		MaxRetries:        2,
		QuestionTypes:     dnsx.DefaultOptions.QuestionTypes,
		Trace:             false,
		TraceMaxRecursion: dnsx.DefaultOptions.TraceMaxRecursion,
		Hostsfile:         false,
		OutputCDN:         false,
	})
	if err != nil {
		fmt.Printf("err: %v\n", err)
		return []string{}, fmt.Errorf("error creating dnsx client: %v", err)
	}

	timeStart := time.Now()

	for _, subdomain := range subdomains {
		res, _ := dnsClient.Lookup(subdomain)

		if len(res) > 1 {
			result = append(result, subdomain)
		}
	}

	fmt.Println("\nCompleted in", time.Since(timeStart))
	return result, nil
}

When I pass 691 subdomains to the DnsxEnrich function, it takes approximately 1 minute and 14 seconds to resolve all the subdomains. In contrast, using dnsx as the CLI tool completes the process in just 1.75 seconds.

Output:

dnsx as CLI

dnsx CLI

dnsx as library

dnsx library

Same question. I read the code, CLI options.Threads default is 100, but use the library don't have the thread option to set.

@dogancanbakir dogancanbakir removed their assignment Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Investigation Something to Investigate Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors.
Projects
None yet
Development

No branches or pull requests

3 participants