Skip to content

Commit

Permalink
chore: Reduce code complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
neriberto committed Dec 17, 2023
1 parent 6c7e4ef commit 1bb0860
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 39 deletions.
41 changes: 2 additions & 39 deletions cmd/hednsextractor/hednsextractor.go
Original file line number Diff line number Diff line change
@@ -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!")
Expand Down Expand Up @@ -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()
}
42 changes: 42 additions & 0 deletions utils/network.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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")
}
}
}
}

0 comments on commit 1bb0860

Please sign in to comment.