From b949d3536ff60f18d6f13ba741d24b1972b961fa Mon Sep 17 00:00:00 2001 From: Jon Hadfield Date: Thu, 24 Oct 2024 14:15:09 +0100 Subject: [PATCH] bump dependencies. --- cmd/ip-fetcher/virustotal.go | 83 ++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 cmd/ip-fetcher/virustotal.go diff --git a/cmd/ip-fetcher/virustotal.go b/cmd/ip-fetcher/virustotal.go new file mode 100644 index 0000000..55e07e6 --- /dev/null +++ b/cmd/ip-fetcher/virustotal.go @@ -0,0 +1,83 @@ +package main + +import ( + "fmt" + "os" + "strings" + + "github.com/jonhadfield/ip-fetcher/providers/abuseipdb" + "github.com/urfave/cli/v2" +) + +func abuseipdbCmd() *cli.Command { + return &cli.Command{ + Name: "abuseipdb", + HelpName: "- fetch AbuseIPDB prefixes", + Usage: "AbuseIPDB", + UsageText: "ip-fetcher abuseipdb --key {--stdout | --path FILE} [--confidence] [--limit]", + OnUsageError: func(cCtx *cli.Context, err error, isSubcommand bool) error { + _ = cli.ShowSubcommandHelp(cCtx) + + return err + }, + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "key", + Usage: "api key", Aliases: []string{"k"}, Required: true, + }, + &cli.IntFlag{ + Name: "confidence", + Usage: "minimum confidence percentage score to return", Value: 75, Aliases: []string{"c"}, + }, + &cli.Int64Flag{ + Name: "limit", + Usage: "maximum number of results to return", Value: 1000, Aliases: []string{"l"}, + }, + &cli.StringFlag{ + Name: "path", + Usage: "where to save the file", Aliases: []string{"p"}, + }, + &cli.BoolFlag{ + Name: "stdout", + Usage: "write to stdout", Aliases: []string{"s"}, + }, + }, + Action: func(c *cli.Context) error { + path := strings.TrimSpace(c.String("path")) + if path == "" && !c.Bool("stdout") { + _ = cli.ShowSubcommandHelp(c) + fmt.Println("\nerror: must specify at least one of stdout and path") + os.Exit(1) + } + + a := abuseipdb.New() + a.Limit = c.Int64("limit") + a.APIKey = c.String("key") + a.ConfidenceMinimum = c.Int("confidence") + data, _, _, err := a.FetchData() + if err != nil { + return err + } + + if path != "" { + var out string + if out, err = saveFile(saveFileInput{ + provider: "abuseipdb", + data: data, + path: path, + defaultFileName: "blacklist", + }); err != nil { + return err + } + + _, _ = os.Stderr.WriteString(fmt.Sprintf("data written to %s\n", out)) + } + + if c.Bool("stdout") { + fmt.Printf("%s\n", data) + } + + return nil + }, + } +}