-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
52 lines (43 loc) · 882 Bytes
/
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
package main
import (
"flag"
"fmt"
"os"
"github.com/melvinsh/asn/pkg/asn"
"github.com/melvinsh/asn/pkg/subnet"
)
func main() {
var ips bool
flag.BoolVar(&ips, "ips", false, "Print IPs instead of subnets")
flag.Parse()
if len(flag.Args()) < 1 {
fmt.Fprintln(os.Stderr, "Usage: asn [-ips] <ASN>")
return
}
subnets, err := asn.FindSubnets(flag.Arg(0))
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
if ips {
printIps(subnets)
} else {
printSubnets(subnets)
}
}
func printIps(subnets []string) {
for _, net := range subnets {
ips, err := subnet.GetIPAddressesInSubnet(net)
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting IP addresses for subnet %s: %v\n", net, err)
}
for _, ip := range ips {
fmt.Println(ip)
}
}
}
func printSubnets(subnets []string) {
for _, subnet := range subnets {
fmt.Println(subnet)
}
}