-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (40 loc) · 962 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
package main
import (
"fmt"
flag "github.com/ogier/pflag"
"github.com/vanytsvetkov/ipcalc/functions"
"net"
)
func main() {
var prefix, separator string
var subnetSize int
flag.IntVarP(&subnetSize, "split", "s", 0, "Division prefix by {int-arg} subnets.")
flag.StringVarP(&separator, "delimiter", "d", "\n", "Join subnets by {str-arg} delimiter.")
flag.Parse()
if flag.NArg() < 1 {
fmt.Println("Usage: ipcalc <prefix>")
flag.PrintDefaults()
return
}
prefix = flag.Arg(0)
_, ipNet, err := net.ParseCIDR(prefix)
if err != nil {
fmt.Println(err)
return
}
ipMask, _ := ipNet.Mask.Size()
ipcalcResult, err := functions.IPcalc(prefix)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(ipcalcResult)
if subnetSize > 0 && subnetSize >= ipMask && subnetSize <= 32 {
ipsplitResult, err := functions.IPsplit(prefix, subnetSize, separator)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(ipsplitResult)
}
}