nuclei/v2/pkg/executer/dns_utils.go

39 lines
812 B
Go
Raw Normal View History

2020-07-16 08:57:28 +00:00
package executer
import (
2020-04-22 20:45:02 +00:00
"net/url"
"github.com/asaskevich/govalidator"
)
2020-04-22 20:45:02 +00:00
// isURL tests a string to determine if it is a well-structured url or not.
func isURL(toTest string) bool {
_, err := url.ParseRequestURI(toTest)
if err != nil {
return false
}
u, err := url.Parse(toTest)
if err != nil || u.Scheme == "" || u.Host == "" {
return false
}
return true
}
2020-04-26 00:20:33 +00:00
// extractDomain extracts the domain name of a URL
func extractDomain(URL string) string {
u, err := url.Parse(URL)
if err != nil {
return ""
}
2020-04-26 00:20:33 +00:00
hostname := u.Hostname()
return hostname
}
2020-04-22 20:45:02 +00:00
// isDNS tests a string to determine if it is a well-structured dns or not
// even if it's oneliner, we leave it wrapped in a function call for
// future improvements
func isDNS(toTest string) bool {
return govalidator.IsDNSName(toTest)
}