maraudir/common/exec.go

64 lines
1.2 KiB
Go
Raw Permalink Normal View History

2024-11-21 06:16:20 +00:00
package common
import (
"fmt"
"log/slog"
"os"
)
func thread(l *slog.Logger, dests <-chan string, tab chan<- interface{}) {
c := MkClient()
for dest := range dests {
uriloop:
for _, uri := range Paths {
url := fmt.Sprintf("https://%s%s", dest, uri)
fallback := true
for {
if doc, err := Hit(c, url); err == nil {
if doc != nil {
if Checktitle(doc) {
entries := Entries(doc)
l.Info("opendir", "url", url, "entries", entries)
}
}
break
} else {
if !fallback {
break uriloop
}
url = fmt.Sprintf("http://%s%s", dest, uri)
fallback = false
}
}
}
}
tab <- "H A C K T H E P L A N E T"
}
func Takeoff() {
dests := make(chan string)
tab := make(chan interface{})
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
for i := 0; i < Conf.Threads; i++ {
go thread(logger, dests, tab)
}
if Conf.List != "" {
Readfile(Conf.List, dests)
} else if Conf.Cidr != "" {
if !ValidRange(Conf.Cidr) {
Fatal("invalid cidr range")
}
LCG(Conf.Cidr, dests)
} else {
Fatal("provide either a list (-l) or cidr range (-r)")
}
close(dests)
for x := 0; x < Conf.Threads; x++ {
<-tab
}
close(tab)
}