Skip to content

Commit

Permalink
bump dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhadfield committed Oct 24, 2024
1 parent 0d979e7 commit b949d35
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions cmd/ip-fetcher/virustotal.go
Original file line number Diff line number Diff line change
@@ -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 {

Check failure on line 12 in cmd/ip-fetcher/virustotal.go

View workflow job for this annotation

GitHub Actions / lint

abuseipdbCmd redeclared in this block
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
},
}
}

0 comments on commit b949d35

Please sign in to comment.