2020-07-16 08:57:28 +00:00
|
|
|
package executer
|
2020-04-04 10:29:05 +00:00
|
|
|
|
|
|
|
import (
|
2020-04-22 20:45:02 +00:00
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"github.com/asaskevich/govalidator"
|
2020-04-04 10:29:05 +00:00
|
|
|
)
|
|
|
|
|
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
|
2020-04-24 13:19:43 +00:00
|
|
|
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-24 13:19:43 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
}
|