Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion dist/Discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ class Discovery {
version: '',
platform: '',
uptime: 0,
board: ''
softwareId: '',
board: '',
unpack: 0,
interfaceName: ''
};
/**
* Mikrotik FirstByte starts at 8
Expand Down Expand Up @@ -57,9 +60,18 @@ class Discovery {
case 10: // uptime
device.uptime = Buffer.from(this.msg.slice(offset, offset + attrLength)).readUInt32LE(0);
break;
case 11: // software id
device.softwareId = format_1.bin2String(this.msg.subarray(offset, offset + attrLength));
break;
case 12: // board
device.board = format_1.bin2String(this.msg.subarray(offset, offset + attrLength));
break;
case 14: // unpack (discovery packet compresson type) (none|simple|uncompressed-headers|uncompressed-all)
device.unpack = Buffer.from(this.msg.slice(offset, offset + attrLength)).readInt8(0);
break;
case 16: // interface name
device.interfaceName = format_1.bin2String(this.msg.subarray(offset, offset + attrLength));
break;
default: // unknown type
console.debug('unknown mndp message type', attrType);
break;
Expand Down
13 changes: 13 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,17 @@ export declare class NodeMndp extends events.EventEmitter {
* Initalize Listeners
*/
private registerListeners();
/**
* Instigate responses from neighbors.
*
* According to Wireshark on Windows, pressing the Refresh button on Mikrotik's
* WinBox tool causes it to send three packets:
* 1. to 255.255.255.255
* 2. to your subnet's broadcast address, e.g. 192.168.1.255
* 3. to 239.255.255.255
* The first one works but it causes the server to pick up the packet.
* The second one I am not sure how to correctly acquire the IP for, so I skipped.
* The third seems to work best because it works without causing our server to react.
*/
refresh(portOverride?: null): void;
}
20 changes: 20 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,25 @@ class NodeMndp extends events.EventEmitter {
this.server.setBroadcast(true);
});
}
/**
* Instigate responses from neighbors.
*
* According to Wireshark on Windows, pressing the Refresh button on Mikrotik's
* WinBox tool causes it to send three packets:
* 1. to 255.255.255.255
* 2. to your subnet's broadcast address, e.g. 192.168.1.255
* 3. to 239.255.255.255
* The first one works but it causes the server to pick up the packet.
* The second one I am not sure how to correctly acquire the IP for, so I skipped.
* The third seems to work best because it works without causing our server to react.
*/
refresh(portOverride = null) {
if (!this.started)
return;
let port = portOverride || this.port;
let buf = Buffer.alloc(4);
buf.fill(0);
this.server.send(buf, 0, 4, port, '239.255.255.255');
}
}
exports.NodeMndp = NodeMndp;
3 changes: 3 additions & 0 deletions dist/interfaces/device.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ export interface Device {
identity: string;
platform: string;
uptime: number;
softwareId: string;
board: string;
unpack: number;
interfaceName: string;
}
14 changes: 13 additions & 1 deletion lib/Discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export class Discovery {
version: '',
platform: '',
uptime: 0,
board: ''
softwareId: '',
board: '',
unpack: 0,
interfaceName: ''
};

/**
Expand Down Expand Up @@ -67,9 +70,18 @@ export class Discovery {
case 10: // uptime
device.uptime = Buffer.from(this.msg.slice(offset, offset + attrLength)).readUInt32LE(0);
break;
case 11: // software id
device.softwareId = bin2String(this.msg.subarray(offset, offset + attrLength));
break;
case 12: // board
device.board = bin2String(this.msg.subarray(offset, offset + attrLength));
break;
case 14: // unpack (discovery packet compresson type) (none|simple|uncompressed-headers|uncompressed-all)
device.unpack = Buffer.from(this.msg.slice(offset, offset + attrLength)).readInt8(0);
break;
case 16: // interface name
device.interfaceName = bin2String(this.msg.subarray(offset, offset + attrLength));
break;
default: // unknown type
console.debug('unknown mndp message type', attrType);
break;
Expand Down
23 changes: 23 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,27 @@ export class NodeMndp extends events.EventEmitter {
this.server.setBroadcast(true);
})
}

/**
* Instigate responses from neighbors.
*
* According to Wireshark on Windows, pressing the Refresh button on Mikrotik's
* WinBox tool causes it to send three packets:
* 1. to 255.255.255.255
* 2. to your subnet's broadcast address, e.g. 192.168.1.255
* 3. to 239.255.255.255
* The first one works but it causes the server to pick up the packet.
* The second one I am not sure how to correctly acquire the IP for, so I skipped.
* The third seems to work best because it works without causing our server to react.
*/
refresh(portOverride=null): void
{
if (!this.started)
return;

let port = portOverride || this.port;
let buf = Buffer.alloc(4);
buf.fill(0);
this.server.send(buf, 0, 4, port, '239.255.255.255');
}
}
3 changes: 3 additions & 0 deletions lib/interfaces/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ export interface Device {
identity: string;
platform: string;
uptime: number;
softwareId: string;
board: string;
unpack: number;
interfaceName: string;
}
21 changes: 15 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

This is an implementation written in Node

NOTE: The library does **not** automatically send a "refresh" packet to cause neighbors to announce themselves, but the function is implemented and available in the API as `refresh()`.

### Usage Example
```
var NodeMndp = require('node-mndp');
var discovery = new NodeMndp({
var mndp = require('node-mndp').NodeMndp;
var discovery = new mndp({
port: 5678
});

Expand All @@ -20,8 +21,8 @@ discovery.start();

Ipv6 Example
```
var NodeMndp = require('node-mndp');
var discovery = new NodeMndp({
var mndp = require('node-mndp').NodeMndp;
var discovery = new mndp({
port: 5678,
host: "::",
version: "udp6"
Expand All @@ -35,8 +36,8 @@ discovery.start();
```
### API
```
var NodeMndp = require('node-mndp');
var discovery = new NodeMndp({
var mndp = require('node-mndp').NodeMndp;
var discovery = new mndp({
port: 5678
});
```
Expand All @@ -54,6 +55,8 @@ options {

#### discovery.stop() -> void

#### discovery.refresh() -> void

#### Event: 'deviceFound'
```

Expand All @@ -63,6 +66,12 @@ Output:
"macAddress":"aabbccddeeff",
"identity":"Mikrotik",
"version":"6.41.2 (stable)"
"platform":"MikroTik",
"uptime":12190,
"softwareId":"8C0S-DDXE",
"board":"RB2011UiAS-2HnD",
"unpack":0,
"interfaceName":"LAN_Bridge/ether2"
}

```
Expand Down
1 change: 1 addition & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test.on('deviceFound', (output) => {

test.on('started', (output) => {
console.log(output);
test.refresh();
});

test.on('error', (output) => {
Expand Down