Go library for accessing Mikrotik devices using the RouterOS API.
Look in the examples directory to learn how to use this library: run, listen, tab.
API documentation is available at godoc.org. Page on the Mikrotik Wiki.
Go library for accessing Mikrotik devices using the RouterOS API
License: MIT License
Please change login method for supporting routeros 6.45.1 and newer:
https://wiki.mikrotik.com/wiki/Manual:API#Initial_login
I am writing a program that should disable devices. But when the command is sent, the microtik responds "!done @ []" and nothing happens.
reply, _:= clientROS.Run("/ip/dhcp-server/lease/set", "?disabled=yes", "?numbers="+id)
where "id" is obtained as id = re.Map [". id"]
I tried and so
reply, _:= clientROS.Run("/ip/dhcp-server/lease/disable", "?numbers="+id)
What am I doing wrong?
For API v6 request /ip/firewall/address-list/listen looks like /ip firewall address-list listen
when I change line 13 master/examples/listen/main.go
to
command = flag.String("command", "/ip firewall address-list listen", "RouterOS command")
I have error
from RouterOS device: no such command
exit status 1
Good day.
When using this library, an error occurs:
panic: runtime error: slice bounds out of range [:4380] with capacity 4096
goroutine 11 [running]:
bufio.(*Reader).Read(0xc0000556e0, 0xc0028c6a4e, 0x1, 0x1, 0x0, 0x0, 0x0)
C:/Go/src/bufio/bufio.go:238 +0x3da
io.ReadAtLeast(0xa1da20, 0xc0000065b8, 0xc0028c6a4e, 0x1, 0x1, 0x1, 0x9, 0x1acac200a28, 0x30)
C:/Go/src/io/io.go:328 +0x8e
io.ReadFull(...)
C:/Go/src/io/io.go:347
gopkg.in/routeros.v2/proto.(*reader).readNumber(0xc0000065b8, 0x1, 0x5321d8, 0x100000000000030, 0x1acd1a77e68)
C:/Users/root/go/src/github.com/rid-lin/gomtc/vendor/gopkg.in/routeros.v2/proto/reader.go:62 +0x85
gopkg.in/routeros.v2/proto.(*reader).readLength(0xc0000065b8, 0xc0028c6a40, 0x9, 0xc000046c01)
C:/Users/root/go/src/github.com/rid-lin/gomtc/vendor/gopkg.in/routeros.v2/proto/reader.go:74 +0x3f
gopkg.in/routeros.v2/proto.(*reader).readWord(0xc0000065b8, 0xc001b096e0, 0xc0028c6a40, 0x9, 0xc00329c1c8, 0x1)
C:/Users/root/go/src/github.com/rid-lin/gomtc/vendor/gopkg.in/routeros.v2/proto/reader.go:100 +0x36
gopkg.in/routeros.v2/proto.(*reader).ReadSentence(0xc0000065b8, 0xc001d64e20, 0x0, 0xcaa5c8)
C:/Users/root/go/src/github.com/rid-lin/gomtc/vendor/gopkg.in/routeros.v2/proto/reader.go:28 +0x8f
gopkg.in/routeros%2ev2.(*Client).readReply(0xc000055740, 0x0, 0x0, 0xc0018ab5e0)
C:/Users/root/go/src/github.com/rid-lin/gomtc/vendor/gopkg.in/routeros.v2/reply.go:29 +0x62
gopkg.in/routeros%2ev2.(*Client).endCommandSync(0xc000055740, 0xc0018ab5a0, 0x1d, 0x0)
C:/Users/root/go/src/github.com/rid-lin/gomtc/vendor/gopkg.in/routeros.v2/run.go:42 +0x7c
gopkg.in/routeros%2ev2.(*Client).RunArgs(0xc000055740, 0xc0032298a0, 0x3, 0x3, 0xe, 0xc0018ab5a0, 0x1d)
C:/Users/root/go/src/github.com/rid-lin/gomtc/vendor/gopkg.in/routeros.v2/run.go:26 +0x171
What can you advise?
Hi,
Winbox and mactelnet can connect to mikrotik with MAC address. It is possible to add such functionality?
in terminal i run “interface print stats” ,
in this lib ,what write ?
"/interface/print/stats" return faslse
As a lot of people may be using v2
, the plain login commit should be merged in v2
.
And in fact, looking at all the other changes in master
, there is no breaking API stuff between master
and v2
, so you can just as will merge all commits to v2
.
Is this library abandoned?
Old API authentication method will also no longer work, see documentation for new login procedure:
https://wiki.mikrotik.com/wiki/Manual:API#Initial_login
Need update dial method to connect into MK.
Hello,
Any chance of making a bit higher level API as well?
like
// Create new mikrotik api client
client := mikrotik.NewClientApi("192.168.88.1:8728")
if err := client.Connect("admin", ""); err != nil {
log.Fatalf("Failed to connect: %s", err.Error())
}
defer client.Close()
// Obtain system information
system, err := client.System()
check(err)
// Obtain system resource information
resources, err := system.Resources();
check(err)
// Print some system resources
log.Printf("Uptime: %s", resources.Uptime)
log.Printf("Version: %s", resources.Version)
log.Printf("Build-time: %s", resources.BuildTime)
// ..
// Obtain information about interfaces
iface, err := client.Interface()
check(err)
// Print basic info about each interface
for idx, iface := range iface.ToArray() {
log.Printf("Interface: #%d %s Type: %s Mac: %s", idx, iface.Name, iface.Type, iface.MacAddress)
}
hi
can we keep it connect for example for 24 hours ?
how can we detect it disconnect and reconnect again?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.