summaryrefslogtreecommitdiffstats
path: root/cmd/crawl.go
blob: 5c5f78f3c8c9ecba636951e7a1d60f76c1830370 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package cmd

import (
	"fmt"

	"github.com/spf13/cobra"
)

var crawlCmd = &cobra.Command{
	Use:     "crawl [domain]",
	Aliases: []string{"cw"},
	Short:   "Crawl domain",
	Long:    `Resolves a domain using httpx and crawls it using katana. Returns discovered links as plain text, one per line, streamed in real-time. Supports both http:// and https:// URLs.`,
	Args:    argsOrStdin(1),
	RunE:    runCrawl,
}

func init() {
	rootCmd.AddCommand(crawlCmd)
	crawlCmd.Flags().Bool("subdomains", false, "Also discover and crawl all subdomains using subfinder")
}

func runCrawl(cmd *cobra.Command, args []string) error {
	subdomains, _ := cmd.Flags().GetBool("subdomains")

	c, err := newUnauthenticatedClient()
	if err != nil {
		return err
	}

	return forEachQuery(args, func(domain string) error {
		return c.CrawlDomain(domain, subdomains, func(line string) error {
			fmt.Println(line)
			return nil
		})
	})
}