mirror of
https://github.com/projectdiscovery/httpx.git
synced 2024-12-01 12:13:00 +03:00
Adding support for custom resolvers
This commit is contained in:
parent
430a180e42
commit
96a511ad48
@ -44,6 +44,9 @@ func New(options *Options) (*HTTPX, error) {
|
||||
fastdialerOpts.Deny = options.Deny
|
||||
fastdialerOpts.Allow = options.Allow
|
||||
fastdialerOpts.WithDialerHistory = true
|
||||
if len(options.Resolvers) > 0 {
|
||||
fastdialerOpts.BaseResolvers = options.Resolvers
|
||||
}
|
||||
dialer, err := fastdialer.NewDialer(fastdialerOpts)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not create resolver cache: %s", err)
|
||||
|
@ -36,6 +36,7 @@ type Options struct {
|
||||
MaxResponseBodySizeToSave int64
|
||||
MaxResponseBodySizeToRead int64
|
||||
UnsafeURI string
|
||||
Resolvers []string
|
||||
}
|
||||
|
||||
// DefaultOptions contains the default options
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"math"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/projectdiscovery/fileutil"
|
||||
"github.com/projectdiscovery/goconfig"
|
||||
@ -197,6 +198,7 @@ type Options struct {
|
||||
Stream bool
|
||||
SkipDedupe bool
|
||||
ProbeAllIPS bool
|
||||
Resolvers goflags.NormalizedStringSlice
|
||||
}
|
||||
|
||||
// ParseOptions parses the command line options for application
|
||||
@ -288,6 +290,7 @@ func ParseOptions() *Options {
|
||||
flagSet.BoolVarP(&options.Stream, "stream", "s", false, "Stream mode - start elaborating input targets without sorting"),
|
||||
flagSet.BoolVarP(&options.SkipDedupe, "skip-dedupe", "sd", false, "Disable dedupe input items (only used with stream mode)"),
|
||||
flagSet.BoolVarP(&options.ProbeAllIPS, "probe-all-ips", "pa", false, "Probe all the ips associated with same host"),
|
||||
flagSet.NormalizedStringSliceVarP(&options.Resolvers, "resolvers", "r", []string{}, "List of resolvers (file or comma separated) - each resolver can be in the form protocol:ip|hostname:port - invalid files/resolvers ignored"),
|
||||
)
|
||||
|
||||
createGroup(flagSet, "debug", "Debug",
|
||||
@ -370,6 +373,26 @@ func (options *Options) validateOptions() {
|
||||
gologger.Fatal().Msgf("Invalid value for match regex option: %s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
var resolvers []string
|
||||
for _, resolver := range options.Resolvers {
|
||||
if fileutil.FileExists(resolver) {
|
||||
chFile, err := fileutil.ReadFile(resolver)
|
||||
if err != nil {
|
||||
gologger.Fatal().Msgf("Couldn't process resolver file \"%s\": %s\n", resolver, err)
|
||||
}
|
||||
for line := range chFile {
|
||||
resolvers = append(resolvers, line)
|
||||
}
|
||||
} else {
|
||||
resolvers = append(resolvers, resolver)
|
||||
}
|
||||
}
|
||||
options.Resolvers = resolvers
|
||||
if len(options.Resolvers) > 0 {
|
||||
gologger.Debug().Msgf("Using resolvers: %s\n", strings.Join(options.Resolvers, ","))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// configureOutput configures the output on the screen
|
||||
|
@ -108,6 +108,7 @@ func New(options *Options) (*Runner, error) {
|
||||
if httpxOptions.MaxResponseBodySizeToSave > httpxOptions.MaxResponseBodySizeToRead {
|
||||
httpxOptions.MaxResponseBodySizeToSave = httpxOptions.MaxResponseBodySizeToRead
|
||||
}
|
||||
httpxOptions.Resolvers = options.Resolvers
|
||||
|
||||
var key, value string
|
||||
httpxOptions.CustomHeaders = make(map[string]string)
|
||||
|
Loading…
Reference in New Issue
Block a user