-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
59 lines (54 loc) · 1.36 KB
/
main.go
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
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/alecthomas/kingpin/v2"
"github.com/franzramadhan/cidrlist/providers"
)
var (
app = kingpin.New("cidrlist", "A command-line tool to fetch IP address ranges from well known providers.")
getIp = app.Command("get", "Get IP from provider (cloudflare, akamai, aws, gcp, and google).")
providerName = getIp.Arg("provider", "The name of the provider.").Required().String()
)
func main() {
switch kingpin.MustParse(app.Parse(os.Args[1:])) {
case getIp.FullCommand():
switch name := *providerName; name {
case "akamai":
ips, err := providers.AkamaiIps()
if err != nil {
panic(err)
}
fmt.Printf("%s:\n%s", strings.ToUpper(name), ips)
case "aws":
aws := providers.AwsInputs{}
ips, err := aws.AwsIps()
if err != nil {
panic(err)
}
fmt.Printf("%s:\n%s", strings.ToUpper(name), ips)
case "cloudflare":
ips, err := providers.CloudflareIps()
if err != nil {
panic(err)
}
fmt.Printf("%s:\n%s", strings.ToUpper(name), ips)
case "gcp":
ips, err := providers.GcpIps()
if err != nil {
panic(err)
}
fmt.Printf("%s:\n%s", strings.ToUpper(name), ips)
case "google":
ips, err := providers.GoogleIps()
if err != nil {
panic(err)
}
fmt.Printf("%s:\n%s", strings.ToUpper(name), ips)
case "":
log.Fatal("invalid provider")
}
}
}