Skip to content
@deckyard/mactelnet

mactelnet cheatsheet

Every export of @deckyard/mactelnet. Background is in the introduction.

jennifer
import "@deckyard/mactelnet/" as mactelnet;

A failed or refused login, an unknown local interface and a malformed MAC address throw an Error of kind "mactelnet". A router that does not answer is kind "timeout", console output left unread past 1 Mi characters (MAX_CONSOLE_CHARS) kind "limit"; a socket failure comes from net unchanged.

Types

Options

FieldMeaning
iface as stringlocal network interface
mac as stringrouter MAC address
user as stringlogin user
password as stringlogin password, "" for none
allowLegacyMd5 as boolaccept the MD5 login of RouterOS™ before 6.43; default false

Session

FieldMeaning
sock as net.UDPSocketthe broadcast socket
state as kv.Storesend and receive counters, buffered output
srcmac as byteslocal interface MAC, 6 bytes
dstmac as bytesrouter MAC, 6 bytes
seskey as int16-bit session key

Sessions

FunctionReturnsNotes
mactelnet.connect(iface, mac, user, password)Sessionsession start and EC-SRP login; a router offering only MD5 is refused
mactelnet.options(iface, mac, user, password)Optionswhat connect uses, allowLegacyMd5 off
mactelnet.connectWith(opts)Sessionconnect with options; MD5 only with allowLegacyMd5
mactelnet.send(s, text)console input; end a command with "\r\n"
mactelnet.recv(s, timeoutMs)stringoutput so far, waiting at most timeoutMs
mactelnet.closed(s)boolwhether the router ended the session
mactelnet.close(s)end the session, release the socket

MAC addresses

FunctionReturnsNotes
mactelnet.parseMac(s)bytesaa:bb:cc:dd:ee:ff, - separators or none
mactelnet.formatMac(b)stringlower case, : separated