-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
47 lines (39 loc) · 1004 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
package main
import (
"flag"
"fmt"
"strings"
)
func main() {
var format string
var printHelp bool
flag.StringVar(&format, "format", "ubiquiti", "The output format")
flag.BoolVar(&printHelp, "help", false, "Print help message")
flag.Parse()
if printHelp {
fmt.Print(helpMessage())
return
}
routes := parseInputFile(flag.Arg(0))
var hexoutput []string
for _, line := range routes {
tmp := strings.Fields(line)
network, destination := tmp[0], tmp[1]
hexoutput = append(hexoutput, network2hex(network)...)
hexoutput = append(hexoutput, ip2hex(destination)...)
}
switch format {
case "opnsense":
fallthrough
case "opensense":
fallthrough
case "ubiquiti":
fmt.Println(strings.Join(hexoutput, ":"))
case "dhcp":
fmt.Println("0x" + strings.ToUpper(strings.Join(hexoutput, "")))
case "mikrotik":
fmt.Println("/ip dhcp-server option")
fmt.Println("add code=121 name=classless-static-route-option value=0x" +
strings.ToUpper(strings.Join(hexoutput, "")))
}
}