summaryrefslogtreecommitdiff
path: root/cmd/record.go
blob: 9ede8d7c8c387eaa485d0edcba1b8a5d6d3054e7 (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
38
39
40
41
42
43
44
45
46
47
package cmd

import (
	"dtool/prober"
	"dtool/utils"

	"fmt"

	"github.com/spf13/cobra"
)

var record_input string
var record_output string
var record_type string
var record_domain string
var recordCmd = &cobra.Command{
	Use:   "record",
	Short: "get specific record response",
	Long:  "get specific record response",
	Run:   record_probe,
}

func record_probe(cmd *cobra.Command, args []string) {
	if len(args) == 1 {
		if utils.IsValidIP(args[0]) {
			result, err := prober.SVCBProbeOnce(args[0], record_domain)
			if err == nil {
				if output_str, err := prober.OutputHandler(result); err == nil {
					fmt.Println(output_str)
				}
			} else {
				fmt.Println(err)
			}
		}
	} else {
		prober.CreateTask(prober.SVCBProbe, record_domain, record_input, record_output, 500)
	}
}

func init() {
	recordCmd.Flags().StringVarP(&record_input, "input", "i", "", "input file(optional)")
	recordCmd.Flags().StringVarP(&record_output, "output", "o", "", "output file(optional)")
	recordCmd.MarkFlagsRequiredTogether("input", "output")
	recordCmd.Flags().StringVarP(&record_type, "type", "t", "A", "request record type")
	recordCmd.Flags().StringVarP(&record_domain, "domain", "d", "example.com", "requested domain")
	rootCmd.AddCommand(recordCmd)
}