Mikrotik

package module
v0.0.0-...-f257236 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2019 License: MIT Imports: 9 Imported by: 0

README

Mikrotik-API

To download this repo use

go get github.com/HeinOldewage/Mikrotik-API

Import as

import Mikrotik "github.com/HeinOldewage/Mikrotik-API"

An example usage

	router := Mikrotik.New()

	err := router.Connect("ipAdress:8728")
	if err != nil {
		log.Fatal(err)
	}

	err = router.Login("username", "password")
	if err != nil {
		log.Fatal(err)
	}

	sen := make(Mikrotik.Sentence, 0)
	sen.Add(Mikrotik.Command("/interface/wireless/registration-table/listen"))

	ch, tag, err := router.SendSentence(sen)

	if err != nil {
		log.Fatal(err)
	}

	for res := range ch {
		log.Println(res)
	}

Note that this API supports commands that have continuous output (like listen and ping). Multiple commands can also be run concurrently. This is facilitated by using tags.

To stop a long running commmand do the following, where tag is the tag is returned from SendSentence.

sen = make(Mikrotik.Sentence, 0)
sen.Add(Mikrotik.Command("/cancel"))
sen.Add(Mikrotik.Attribute("tag", tag))
_, _, err := router.SendSentence(sen)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Router

type Router struct {
	// contains filtered or unexported fields
}

func New

func New() *Router

func (*Router) Close

func (r *Router) Close() error

func (*Router) Connect

func (r *Router) Connect(addr string) error

func (*Router) Login

func (r *Router) Login(user, pass string) error

func (*Router) SendSentence

func (r *Router) SendSentence(mess Sentence) (response chan Sentence, tag string, err error)

type Sentence

type Sentence []Word

func (*Sentence) Add

func (s *Sentence) Add(w Word)

func (*Sentence) Contains

func (s *Sentence) Contains(w Word) bool

func (Sentence) Encode

func (s Sentence) Encode() []byte

func (*Sentence) Get

func (s *Sentence) Get(ss string) (Word, bool)

func (*Sentence) Index

func (s *Sentence) Index(ss string) int

type Word

type Word []byte

func APIAttribute

func APIAttribute(key, val string) Word

func Attribute

func Attribute(key, val string) Word

func Command

func Command(s string) Word

func Decode

func Decode(b []byte) (Word, int, error)

func Query

func Query(key, val string) Word

func (Word) String

func (w Word) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL