forked from go-routeros/routeros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
executable file
·46 lines (37 loc) · 891 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
package main
import (
"flag"
"log"
"strings"
"github.com/hainguyen8y/routeros"
)
var (
command = flag.String("command", "/system/resource/print", "RouterOS command")
address = flag.String("address", "127.0.0.1:8728", "RouterOS address and port")
username = flag.String("username", "admin", "User name")
password = flag.String("password", "admin", "Password")
async = flag.Bool("async", false, "Use async code")
useTLS = flag.Bool("tls", false, "Use TLS")
)
func dial() (*routeros.Client, error) {
if *useTLS {
return routeros.DialTLS(*address, *username, *password, nil)
}
return routeros.Dial(*address, *username, *password)
}
func main() {
flag.Parse()
c, err := dial()
if err != nil {
log.Fatal(err)
}
defer c.Close()
if *async {
c.Async()
}
r, err := c.RunArgs(strings.Split(*command, " "))
if err != nil {
log.Fatal(err)
}
log.Print(r)
}