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

add custom dns addr flag #399

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type arguments struct {
MaxConnections int `short:"c" long:"max-connections" value-name:"<count>" default:"512" description:"Maximum number of HTTP connections"`
MaxConnectionsPerHost int `long:"max-connections-per-host" value-name:"<count>" default:"512" description:"Maximum number of HTTP connections per host"`
MaxResponseBodySize int `long:"max-response-body-size" value-name:"<size>" default:"10000000" description:"Maximum response body size to read"`
CustomDnsAddr string `long:"custom-dns-addr" description:"Custom DNS server to be used for requests"`
RawExcludedPatterns []string `short:"e" long:"exclude" value-name:"<pattern>..." description:"Exclude URLs matched with given regular expressions"`
RawIncludedPatterns []string `short:"i" long:"include" value-name:"<pattern>..." description:"Include URLs matched with given regular expressions"`
FollowRobotsTxt bool `long:"follow-robots-txt" description:"Follow robots.txt when scraping pages"`
Expand Down
1 change: 1 addition & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (c *command) runWithError(ss []string) (bool, error) {
SkipTLSVerification: args.SkipTLSVerification,
Timeout: time.Duration(args.Timeout) * time.Second,
Header: args.Header,
CustomDnsAddr: args.CustomDnsAddr,
},
),
args.RateLimit,
Expand Down
18 changes: 18 additions & 0 deletions fasthttp_http_client_factory.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"crypto/tls"
"net"

Expand All @@ -24,6 +25,23 @@ func (*fasthttpHttpClientFactory) Create(o httpClientOptions) httpClient {
d = fasthttpproxy.FasthttpHTTPDialerTimeout(o.Proxy, tcpTimeout)
}

if o.CustomDnsAddr != "" {
d = func(addr string) (net.Conn, error) {
dialer := fasthttp.TCPDialer{
Concurrency: 1000,
Resolver: &net.Resolver{
PreferGo: true,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any particular reason you enabled this option?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think if we don't enable this option, it uses the DNS resolver of our operating system, I tried sniffing the DNS packets through wireshark, the custom dns resolver was used only if I turn on this flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have a look at golang/go#35561 (comment)

Copy link
Owner

@raviqqe raviqqe Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! I reverted it back. Can you test the main branch again?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure will do and get back to you !

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @raviqqe just tested it, seems to be working fine

image

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

StrictErrors: false,
Dial: func(ctx context.Context, network string, address string) (net.Conn, error) {
internalDialer := net.Dialer{}
return internalDialer.DialContext(ctx, "udp", o.CustomDnsAddr)
},
},
}
return dialer.DialTimeout(addr, tcpTimeout)
}
}

return newFasthttpHttpClient(
&fasthttp.Client{
MaxConnsPerHost: o.MaxConnectionsPerHost,
Expand Down
4 changes: 4 additions & 0 deletions fasthttp_http_client_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ func TestFasthttpHttpClientFactoryCreate(t *testing.T) {
func TestFasthttpHttpClientFactoryCreateWithProxy(t *testing.T) {
newFasthttpHttpClientFactory().Create(httpClientOptions{Proxy: "foo"})
}

func TestFasthttpHttpClientFactoryCreateWithCustomDnsResolver(t *testing.T) {
newFasthttpHttpClientFactory().Create(httpClientOptions{CustomDnsAddr: "1.1.1.1:53"})
}
1 change: 1 addition & 0 deletions http_client_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type httpClientOptions struct {
SkipTLSVerification bool
Timeout time.Duration
Header http.Header
CustomDnsAddr string
}

type httpClientFactory interface {
Expand Down
Loading