diff --git a/cmd/hednsextractor/hednsextractor.go b/cmd/hednsextractor/hednsextractor.go index 54b68ea..480ec27 100644 --- a/cmd/hednsextractor/hednsextractor.go +++ b/cmd/hednsextractor/hednsextractor.go @@ -1,26 +1,15 @@ package main import ( - "bufio" - "os" - "strconv" - "github.com/HuntDownProject/hednsextractor/utils" "github.com/projectdiscovery/goflags" "github.com/projectdiscovery/gologger" "github.com/projectdiscovery/gologger/levels" - fileutil "github.com/projectdiscovery/utils/file" ) func main() { - // Look into stdin to grab the IPv4s and Networks - if fileutil.HasStdin() { - s := bufio.NewScanner(os.Stdin) - for s.Scan() { - utils.IdentifyTarget(s.Text()) - } - } + utils.ParseStdin() flagSet := goflags.NewFlagSet() flagSet.SetDescription("HEDnsExtractor - Raw html extractor from Hurricane Electric portal!") @@ -56,31 +45,5 @@ func main() { utils.IdentifyTarget(utils.OptionCmd.Target) } - if len(utils.Domains) > 0 { - for i := range utils.Domains { - utils.ExtractDomain(utils.Domains[i], utils.OptionCmd.Silent) - } - } - - // for each IPv4 look for their Network - if len(utils.Hosts) > 0 { - for i := range utils.Hosts { - utils.ExtractNetwork( - utils.Hosts[i], - utils.OptionCmd.Silent, - utils.OptionCmd.Onlydomains, - utils.OptionCmd.Onlynetworks) - } - } - - // for each network, enumerate the domains - if len(utils.Networks) > 0 && !utils.OptionCmd.Onlynetworks { - for i := range utils.Networks { - if score, err := strconv.ParseUint(utils.OptionCmd.VtscoreValue, 10, 64); err == nil { - utils.ExtractDomains(utils.Networks[i], utils.OptionCmd.Silent, utils.OptionCmd.Vtscore, score) - } else { - gologger.Fatal().Msg("Invalid parameter value for vt-score") - } - } - } + utils.RunCrawler() } diff --git a/utils/network.go b/utils/network.go index 9208f31..c19782a 100644 --- a/utils/network.go +++ b/utils/network.go @@ -1,12 +1,16 @@ package utils import ( + "bufio" "net" "net/http/httputil" + "os" "regexp" + "strconv" "github.com/projectdiscovery/gologger" "github.com/projectdiscovery/retryablehttp-go" + fileutil "github.com/projectdiscovery/utils/file" ) func contains(s []string, e string) bool { @@ -18,6 +22,16 @@ func contains(s []string, e string) bool { return false } +func ParseStdin() { + // Look into stdin to grab the IPv4s and Networks + if fileutil.HasStdin() { + s := bufio.NewScanner(os.Stdin) + for s.Scan() { + IdentifyTarget(s.Text()) + } + } +} + func IsIpAddr(ipAddr string) bool { addr := net.ParseIP(ipAddr) return addr != nil @@ -130,3 +144,31 @@ func ExtractDomains(ipRange string, silent bool, vtscore bool, vtscoreValue uint } } } + +func RunCrawler() { + if len(Domains) > 0 { + for i := range Domains { + ExtractDomain(Domains[i], OptionCmd.Silent) + } + } + + if len(Hosts) > 0 { + for i := range Hosts { + ExtractNetwork( + Hosts[i], + OptionCmd.Silent, + OptionCmd.Onlydomains, + OptionCmd.Onlynetworks) + } + } + + if len(Networks) > 0 && !OptionCmd.Onlynetworks { + for i := range Networks { + if score, err := strconv.ParseUint(OptionCmd.VtscoreValue, 10, 64); err == nil { + ExtractDomains(Networks[i], OptionCmd.Silent, OptionCmd.Vtscore, score) + } else { + gologger.Fatal().Msg("Invalid parameter value for vt-score") + } + } + } +}