2021-04-18 11:57:43 +02:00
|
|
|
package protocolstate
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
|
"github.com/projectdiscovery/fastdialer/fastdialer"
|
|
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/types"
|
|
|
|
|
)
|
|
|
|
|
|
2021-06-14 17:14:16 +05:30
|
|
|
// Dialer is a shared fastdialer instance for host DNS resolution
|
2021-04-18 11:57:43 +02:00
|
|
|
var Dialer *fastdialer.Dialer
|
|
|
|
|
|
2021-06-14 17:14:16 +05:30
|
|
|
// Init creates the Dialer instance based on user configuration
|
2021-04-18 11:57:43 +02:00
|
|
|
func Init(options *types.Options) error {
|
|
|
|
|
opts := fastdialer.DefaultOptions
|
|
|
|
|
if options.SystemResolvers {
|
|
|
|
|
opts.EnableFallback = true
|
|
|
|
|
}
|
|
|
|
|
if options.ResolversFile != "" {
|
|
|
|
|
opts.BaseResolvers = options.InternalResolversList
|
|
|
|
|
}
|
|
|
|
|
dialer, err := fastdialer.NewDialer(opts)
|
|
|
|
|
if err != nil {
|
2021-04-19 00:55:33 +05:30
|
|
|
return errors.Wrap(err, "could not create dialer")
|
2021-04-18 11:57:43 +02:00
|
|
|
}
|
|
|
|
|
Dialer = dialer
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-14 17:14:16 +05:30
|
|
|
// Close closes the global shared fastdialer
|
2021-04-18 11:57:43 +02:00
|
|
|
func Close() {
|
|
|
|
|
if Dialer != nil {
|
|
|
|
|
Dialer.Close()
|
|
|
|
|
}
|
|
|
|
|
}
|