Skip to content

Commit

Permalink
(feat) adds ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincobain2000 committed Mar 27, 2024
1 parent 3ffbb34 commit 013db3a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
19 changes: 15 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,19 @@ func main() {
hc := pkg.NewHTTPChallenge(options...)
hc.CrawlRecursive(f.url, &wgC)
wgC.Wait()
color.Success.Print("Crawling")
color.Note.Print("Crawling")
color.Secondary.Print("....................")
color.Success.Println("Complete!")
color.Note.Print("URLs Crawled")
color.Secondary.Print("................")
color.Note.Println(hc.TotalURLsCrawled)
color.Note.Print("URLs with Emails")
color.Secondary.Print("............")
color.Note.Println(hc.TotalURLsFound)

color.Note.Print("Ratio")
color.Secondary.Print(".......................")
color.Note.Println(fmt.Sprintf("%.2f", (float64(hc.TotalURLsFound)/float64(hc.TotalURLsCrawled))*100) + "%")

hc.Emails = pkg.UniqueStrings(hc.Emails)
if f.writeToFile != "" {
Expand All @@ -61,9 +71,10 @@ func main() {
color.Secondary.Print(" ....................")
color.Danger.Println("Error writing emails to file", f.writeToFile)
} else {
color.Success.Print("Emails")
color.Secondary.Print(" ....................")
color.Success.Println("Success writing emails to file", f.writeToFile)
color.Note.Print("Emails")
color.Secondary.Print("......................")
color.Note.Print("Success writing emails to file ")
color.Success.Println(f.writeToFile)
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions pkg/crawl.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ type Option func(*Options) error
type HTTPChallenge struct {
browse *browser.Browser

urls []string
Emails []string
options *Options
urls []string
Emails []string
TotalURLsCrawled int
TotalURLsFound int
options *Options
}

func NewHTTPChallenge(opts ...Option) *HTTPChallenge {
Expand Down Expand Up @@ -78,6 +80,7 @@ func (hc *HTTPChallenge) Crawl(url string) []string {
if err != nil {
return urls
}
hc.TotalURLsCrawled++
if hc.options.SleepMillisecond > 0 {
color.Secondary.Print("Sleeping")
color.Secondary.Print("....................")
Expand All @@ -92,8 +95,9 @@ func (hc *HTTPChallenge) Crawl(url string) []string {
emails = FilterOutCommonExtensions(emails)
emails = UniqueStrings(emails)
if len(emails) > 0 {
hc.TotalURLsFound++
color.Note.Print("Emails")
color.Secondary.Print(" ....................")
color.Secondary.Print("......................")
color.Note.Println(fmt.Sprintf("(%d) %s", len(emails), url))
for _, email := range emails {
color.Secondary.Print(" ")
Expand Down

0 comments on commit 013db3a

Please sign in to comment.