rosinterface 1.3.7 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,272 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FirewallWrapper = void 0;
4
+ class FirewallWrapper {
5
+ constructor(client) {
6
+ this.client = client;
7
+ }
8
+ // ==========================================
9
+ // ADDRESS LISTS (Client Isolation & Grouping)
10
+ // ==========================================
11
+ /**
12
+ * **Retrieve: Address Lists (PRINT)**
13
+ *
14
+ * Sends an `/ip/firewall/address-list/print` command to retrieve IP groupings.
15
+ *
16
+ * **Feature: Filtered Search**
17
+ * Highly useful for checking if a specific customer IP is currently flagged
18
+ * in a suspension or walled-garden list.
19
+ *
20
+ * @param filter Optional dictionary to filter results.
21
+ * @param options Advanced write options.
22
+ * @returns A promise resolving to an array of address list entries.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * // 1. Get all IPs currently in the "suspended_users" list
27
+ * const suspended = await mk.firewall.getAddressLists({ "?list": "suspended_users" });
28
+ * * // 2. Check which lists a specific IP belongs to
29
+ * const userLists = await mk.firewall.getAddressLists({ "?address": "192.168.20.50" });
30
+ * ```
31
+ */
32
+ async getAddressLists(filter, options) {
33
+ return this.client.write('/ip/firewall/address-list/print', filter || {}, options);
34
+ }
35
+ /**
36
+ * **Resource Creation: Address List Entry (ADD)**
37
+ *
38
+ * Sends an `/ip/firewall/address-list/add` command to add an IP to a named list.
39
+ *
40
+ * **Feature: Dynamic Grouping & Timeouts**
41
+ * Essential for billing automation. You can add a client to a suspension list
42
+ * indefinitely, or use the `timeout` parameter for temporary bans.
43
+ *
44
+ * @param address The target IP address or subnet (e.g., '192.168.20.50').
45
+ * @param listName The name of the group (e.g., 'suspended_users').
46
+ * @param additionalParams Optional parameters like 'comment' or 'timeout'.
47
+ * @param options Advanced write options.
48
+ * @returns A promise resolving to the API response.
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * // 1. Suspend a user indefinitely for non-payment
53
+ * await mk.firewall.addAddressList('192.168.20.50', 'suspended_users', {
54
+ * comment: 'Invoice #1045 unpaid'
55
+ * });
56
+ * * // 2. Temporarily block an IP for 1 hour (e.g., due to suspicious activity)
57
+ * await mk.firewall.addAddressList('10.0.0.15', 'temp_blacklist', {
58
+ * timeout: '1h',
59
+ * comment: 'Auto-blocked: SSH brute force'
60
+ * });
61
+ * ```
62
+ */
63
+ async addAddressList(address, listName, additionalParams, options) {
64
+ return this.client.write('/ip/firewall/address-list/add', {
65
+ address,
66
+ list: listName,
67
+ ...additionalParams
68
+ }, options);
69
+ }
70
+ /**
71
+ * **Execution Terminator: Delete Address List Entry (REMOVE)**
72
+ *
73
+ * Sends an `/ip/firewall/address-list/remove` command.
74
+ *
75
+ * **Feature: Safe Deletion**
76
+ * Automatically resolves the dynamic `.id` based on the IP and List Name combination
77
+ * before attempting to remove it.
78
+ *
79
+ * @param address The IP address to remove.
80
+ * @param listName The name of the list from which to remove the IP.
81
+ * @param options Advanced write options.
82
+ * @returns A promise resolving to the API response.
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * // 1. Restore service by removing the IP from the suspended list
87
+ * await mk.firewall.removeAddressList('192.168.20.50', 'suspended_users');
88
+ * ```
89
+ */
90
+ async removeAddressList(address, listName, options) {
91
+ const result = await this.getAddressLists({ "?address": address, "?list": listName }, options);
92
+ if (result.length > 0 && result[0]['.id']) {
93
+ return this.client.write('/ip/firewall/address-list/remove', {
94
+ ".id": result[0]['.id']
95
+ }, options);
96
+ }
97
+ throw new Error(`IP '${address}' not found in list '${listName}'.`);
98
+ }
99
+ // ==========================================
100
+ // NAT (Network Address Translation)
101
+ // ==========================================
102
+ /**
103
+ * **Retrieve: NAT Rules (PRINT)**
104
+ *
105
+ * Sends an `/ip/firewall/nat/print` command to list translation rules.
106
+ *
107
+ * @param filter Optional dictionary to filter results.
108
+ * @param options Advanced write options.
109
+ * @returns A promise resolving to an array of NAT rules.
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * // 1. Retrieve all Port Forwarding (dstnat) rules
114
+ * const portForwards = await mk.firewall.getNatRules({ "?chain": "dstnat" });
115
+ * ```
116
+ */
117
+ async getNatRules(filter, options) {
118
+ return this.client.write('/ip/firewall/nat/print', filter || {}, options);
119
+ }
120
+ /**
121
+ * **Resource Creation: NAT Rule (ADD)**
122
+ *
123
+ * Sends an `/ip/firewall/nat/add` command to create routing translations.
124
+ *
125
+ * **Feature: Internet Access & Port Forwarding**
126
+ * Core functionality for giving clients internet access (masquerade) or
127
+ * opening ports for security cameras and servers (dst-nat).
128
+ *
129
+ * @param chain Usually 'srcnat' (for internet access) or 'dstnat' (for port forwarding).
130
+ * @param action The action to perform (e.g., 'masquerade', 'dst-nat', 'accept').
131
+ * @param additionalParams Dictionary defining the traffic match conditions and target.
132
+ * @param options Advanced write options.
133
+ * @returns A promise resolving to the API response.
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * // 1. Provide Internet Access (Masquerade) to a specific subnet
138
+ * await mk.firewall.addNatRule('srcnat', 'masquerade', {
139
+ * "src-address": "192.168.20.0/24",
140
+ * "out-interface": "ether1-WAN",
141
+ * comment: "Main LAN Internet Access"
142
+ * });
143
+ * * // 2. Port Forwarding: Open port 8080 to an internal camera server
144
+ * await mk.firewall.addNatRule('dstnat', 'dst-nat', {
145
+ * protocol: 'tcp',
146
+ * "dst-port": "8080",
147
+ * "in-interface": "ether1-WAN",
148
+ * "to-addresses": "192.168.20.100",
149
+ * "to-ports": "80",
150
+ * comment: "Camera Server Forwarding"
151
+ * });
152
+ * ```
153
+ */
154
+ async addNatRule(chain, action, additionalParams, options) {
155
+ return this.client.write('/ip/firewall/nat/add', {
156
+ chain,
157
+ action,
158
+ ...additionalParams
159
+ }, options);
160
+ }
161
+ /**
162
+ * **Execution Terminator: Delete NAT Rule (REMOVE)**
163
+ *
164
+ * Sends an `/ip/firewall/nat/remove` command.
165
+ *
166
+ * @param comment The exact comment of the rule to delete (safest way to target dynamically).
167
+ * @param options Advanced write options.
168
+ * @returns A promise resolving to the API response.
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * // 1. Remove a specific port forwarding rule by its comment
173
+ * await mk.firewall.removeNatRuleByComment('Camera Server Forwarding');
174
+ * ```
175
+ */
176
+ async removeNatRuleByComment(comment, options) {
177
+ const result = await this.getNatRules({ "?comment": comment }, options);
178
+ if (result.length > 0 && result[0]['.id']) {
179
+ return this.client.write('/ip/firewall/nat/remove', {
180
+ ".id": result[0]['.id']
181
+ }, options);
182
+ }
183
+ throw new Error(`NAT rule with comment '${comment}' not found.`);
184
+ }
185
+ // ==========================================
186
+ // FILTER RULES (Security & Traffic Control)
187
+ // ==========================================
188
+ /**
189
+ * **Retrieve: Filter Rules (PRINT)**
190
+ *
191
+ * Sends an `/ip/firewall/filter/print` command to list security rules.
192
+ *
193
+ * @param filter Optional dictionary to filter results.
194
+ * @param options Advanced write options.
195
+ * @returns A promise resolving to an array of filter rules.
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * // 1. Check for any rules dropping traffic in the forward chain
200
+ * const dropRules = await mk.firewall.getFilterRules({ "?action": "drop", "?chain": "forward" });
201
+ * ```
202
+ */
203
+ async getFilterRules(filter, options) {
204
+ return this.client.write('/ip/firewall/filter/print', filter || {}, options);
205
+ }
206
+ /**
207
+ * **Resource Creation: Filter Rule (ADD)**
208
+ *
209
+ * Sends an `/ip/firewall/filter/add` command to control traffic flow.
210
+ *
211
+ * **Feature: Automated Network Security**
212
+ * Use this to programmatically drop traffic from suspended users, block external
213
+ * DNS queries, or secure the router's management ports.
214
+ *
215
+ * @param chain 'input' (to router), 'forward' (through router), or 'output' (from router).
216
+ * @param action The action to take ('accept', 'drop', 'reject', etc.).
217
+ * @param additionalParams Dictionary defining the match conditions.
218
+ * @param options Advanced write options.
219
+ * @returns A promise resolving to the API response.
220
+ *
221
+ * @example
222
+ * ```typescript
223
+ * // 1. Block Internet access for suspended users (Forward Chain)
224
+ * await mk.firewall.addFilterRule('forward', 'drop', {
225
+ * "src-address-list": "suspended_users",
226
+ * comment: "Block Internet for suspended clients"
227
+ * });
228
+ * * // 2. Protect the router: Drop external DNS requests (Input Chain)
229
+ * await mk.firewall.addFilterRule('input', 'drop', {
230
+ * protocol: 'udp',
231
+ * "dst-port": "53",
232
+ * "in-interface": "ether1-WAN",
233
+ * comment: "Drop external DNS"
234
+ * });
235
+ * ```
236
+ */
237
+ async addFilterRule(chain, action, additionalParams, options) {
238
+ return this.client.write('/ip/firewall/filter/add', {
239
+ chain,
240
+ action,
241
+ ...additionalParams
242
+ }, options);
243
+ }
244
+ /**
245
+ * **State Modification: Enable/Disable Filter Rule (SET)**
246
+ *
247
+ * Sends an `/ip/firewall/filter/set` command to toggle a rule without deleting it.
248
+ *
249
+ * @param comment The exact comment of the rule to toggle.
250
+ * @param disable Boolean true to disable, false to enable.
251
+ * @param options Advanced write options.
252
+ * @returns A promise resolving to the API response.
253
+ *
254
+ * @example
255
+ * ```typescript
256
+ * // 1. Temporarily disable the rule that blocks suspended clients
257
+ * await mk.firewall.toggleFilterRuleByComment('Block Internet for suspended clients', true);
258
+ * ```
259
+ */
260
+ async toggleFilterRuleByComment(comment, disable, options) {
261
+ const result = await this.getFilterRules({ "?comment": comment }, options);
262
+ if (result.length > 0 && result[0]['.id']) {
263
+ return this.client.write('/ip/firewall/filter/set', {
264
+ ".id": result[0]['.id'],
265
+ disabled: disable ? 'yes' : 'no'
266
+ }, options);
267
+ }
268
+ throw new Error(`Filter rule with comment '${comment}' not found.`);
269
+ }
270
+ }
271
+ exports.FirewallWrapper = FirewallWrapper;
272
+ //# sourceMappingURL=FirewallWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FirewallWrapper.js","sourceRoot":"","sources":["../../src/features/FirewallWrapper.ts"],"names":[],"mappings":";;;AAEA,MAAa,eAAe;IAGxB,YAAY,MAAsB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;I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,aAAa,CACf,KAAqC,EACrC,MAAc,EACd,gBAA2D,EAC3D,OAAuB;QAEvB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,yBAAyB,EAAE;YAChD,KAAK;YACL,MAAM;YACN,GAAG,gBAAgB;SACtB,EAAE,OAAO,CAAC,CAAC;IAChB,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,yBAAyB,CAAC,OAAe,EAAE,OAAgB,EAAE,OAAuB;QACtF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;QAE3E,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;YACxC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,yBAAyB,EAAE;gBAChD,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;gBACvB,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;aACnC,EAAE,OAAO,CAAC,CAAC;QAChB,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,6BAA6B,OAAO,cAAc,CAAC,CAAC;IACxE,CAAC;CACJ;AA1SD,0CA0SC"}
@@ -0,0 +1,140 @@
1
+ import { MikrotikClient, IWriteOptions } from "../client/MikrotikClient";
2
+ export declare class IpWrapper {
3
+ private client;
4
+ constructor(client: MikrotikClient);
5
+ /**
6
+ * **Retrieve: DHCP Leases (PRINT)**
7
+ *
8
+ * Sends a `/ip/dhcp-server/lease/print` command to get active or static leases.
9
+ *
10
+ * **Feature: Filtered Search**
11
+ * You can pass a dictionary of parameters to filter the results directly on the router,
12
+ * reducing the amount of data transferred over the network.
13
+ *
14
+ * @param filter Optional dictionary to filter results (e.g., `{"?mac-address": "00:11:22:33:44:55"}`).
15
+ * @param options Advanced write options (idempotency, forced protocol).
16
+ * @returns A promise resolving to an array of DHCP lease objects.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // Find the IP address currently assigned to a specific MAC
21
+ * const leases = await mk.ip.getDhcpLeases({ "?mac-address": "00:11:22:33:44:55" });
22
+ * if (leases.length > 0) {
23
+ * console.log(`Assigned IP: ${leases[0].address}`);
24
+ * }
25
+ * ```
26
+ */
27
+ getDhcpLeases(filter?: Record<string, string>, options?: IWriteOptions): Promise<any[]>;
28
+ /**
29
+ * **Resource Creation: Static Lease (ADD)**
30
+ *
31
+ * Sends an `/ip/dhcp-server/lease/add` command to bind an IP to a MAC address.
32
+ *
33
+ * **Feature: Permanent IP Binding**
34
+ * Essential for IPoE networks where clients require a fixed IP address
35
+ * based on their hardware address without using PPPoE.
36
+ *
37
+ * @param macAddress The hardware MAC address of the client's router/device.
38
+ * @param ipAddress The static IP address to assign.
39
+ * @param server The name of the DHCP server instance (e.g., 'dhcp_lan').
40
+ * @param additionalParams Optional dictionary for extra parameters (comment, client-id).
41
+ * @param options Advanced write options.
42
+ * @returns A promise resolving to the API response.
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * // Assign a static IP to a new customer's router
47
+ * await mk.ip.addStaticLease(
48
+ * '00:11:22:33:44:55',
49
+ * '192.168.20.50',
50
+ * 'dhcp_lan',
51
+ * { comment: 'Customer: Alice Smith - Plan Basic' }
52
+ * );
53
+ * ```
54
+ */
55
+ addStaticLease(macAddress: string, ipAddress: string, server: string, additionalParams?: Record<string, string | boolean | number>, options?: IWriteOptions): Promise<any[]>;
56
+ /**
57
+ * **Execution Terminator: Delete Lease (REMOVE)**
58
+ *
59
+ * Sends an `/ip/dhcp-server/lease/remove` command to delete a lease.
60
+ *
61
+ * **Feature: Safe Deletion**
62
+ * It automatically searches for the dynamic internal ID (`.id`) using the provided IP
63
+ * before attempting to remove it.
64
+ *
65
+ * @param ipAddress The exact IP address of the lease to remove.
66
+ * @param options Advanced write options.
67
+ * @returns A promise resolving to the API response.
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * // Remove a customer's IP binding after service cancellation
72
+ * try {
73
+ * await mk.ip.removeDhcpLease('192.168.20.50');
74
+ * console.log('Lease removed successfully');
75
+ * } catch (error) {
76
+ * console.error(error.message);
77
+ * }
78
+ * ```
79
+ */
80
+ removeDhcpLease(ipAddress: string, options?: IWriteOptions): Promise<any[]>;
81
+ /**
82
+ * **Retrieve: ARP Table (PRINT)**
83
+ *
84
+ * Sends an `/ip/arp/print` command to list current ARP entries.
85
+ *
86
+ * @param filter Optional dictionary to filter results (e.g., searching by interface or IP).
87
+ * @param options Advanced write options.
88
+ * @returns A promise resolving to an array of ARP entries.
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * // Check if a specific IP is reachable at layer 2
93
+ * const arpEntries = await mk.ip.getArpEntries({ "?address": "192.168.20.50" });
94
+ * const isConnected = arpEntries.length > 0;
95
+ * ```
96
+ */
97
+ getArpEntries(filter?: Record<string, string>, options?: IWriteOptions): Promise<any[]>;
98
+ /**
99
+ * **Resource Creation: Static ARP (ADD)**
100
+ *
101
+ * Sends an `/ip/arp/add` command to create a static layer 2 binding.
102
+ *
103
+ * **Feature: Layer 2 Security**
104
+ * Highly recommended for WISP security to prevent IP spoofing when
105
+ * the router interface is set to `reply-only`.
106
+ *
107
+ * @param macAddress The hardware MAC address of the client.
108
+ * @param ipAddress The exact IP address assigned to the client.
109
+ * @param interfaceName The physical or logical interface facing the client.
110
+ * @param options Advanced write options.
111
+ * @returns A promise resolving to the API response.
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * // Secure a static IP customer by binding their MAC to the interface
116
+ * await mk.ip.addStaticArp(
117
+ * '00:11:22:33:44:55',
118
+ * '192.168.20.50',
119
+ * 'ether3_Clients'
120
+ * );
121
+ * ```
122
+ */
123
+ addStaticArp(macAddress: string, ipAddress: string, interfaceName: string, options?: IWriteOptions): Promise<any[]>;
124
+ /**
125
+ * **Execution Terminator: Delete ARP Entry (REMOVE)**
126
+ *
127
+ * Sends an `/ip/arp/remove` command to delete a static or dynamic ARP entry.
128
+ *
129
+ * @param ipAddress The IP address of the ARP entry to delete.
130
+ * @param options Advanced write options.
131
+ * @returns A promise resolving to the API response.
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * // Clean up the ARP table when a client is permanently disconnected
136
+ * await mk.ip.removeArpEntry('192.168.20.50');
137
+ * ```
138
+ */
139
+ removeArpEntry(ipAddress: string, options?: IWriteOptions): Promise<any[]>;
140
+ }
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IpWrapper = void 0;
4
+ class IpWrapper {
5
+ constructor(client) {
6
+ this.client = client;
7
+ }
8
+ // ==========================================
9
+ // DHCP LEASES (Static IP Assignment)
10
+ // ==========================================
11
+ /**
12
+ * **Retrieve: DHCP Leases (PRINT)**
13
+ *
14
+ * Sends a `/ip/dhcp-server/lease/print` command to get active or static leases.
15
+ *
16
+ * **Feature: Filtered Search**
17
+ * You can pass a dictionary of parameters to filter the results directly on the router,
18
+ * reducing the amount of data transferred over the network.
19
+ *
20
+ * @param filter Optional dictionary to filter results (e.g., `{"?mac-address": "00:11:22:33:44:55"}`).
21
+ * @param options Advanced write options (idempotency, forced protocol).
22
+ * @returns A promise resolving to an array of DHCP lease objects.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * // Find the IP address currently assigned to a specific MAC
27
+ * const leases = await mk.ip.getDhcpLeases({ "?mac-address": "00:11:22:33:44:55" });
28
+ * if (leases.length > 0) {
29
+ * console.log(`Assigned IP: ${leases[0].address}`);
30
+ * }
31
+ * ```
32
+ */
33
+ async getDhcpLeases(filter, options) {
34
+ return this.client.write('/ip/dhcp-server/lease/print', filter || {}, options);
35
+ }
36
+ /**
37
+ * **Resource Creation: Static Lease (ADD)**
38
+ *
39
+ * Sends an `/ip/dhcp-server/lease/add` command to bind an IP to a MAC address.
40
+ *
41
+ * **Feature: Permanent IP Binding**
42
+ * Essential for IPoE networks where clients require a fixed IP address
43
+ * based on their hardware address without using PPPoE.
44
+ *
45
+ * @param macAddress The hardware MAC address of the client's router/device.
46
+ * @param ipAddress The static IP address to assign.
47
+ * @param server The name of the DHCP server instance (e.g., 'dhcp_lan').
48
+ * @param additionalParams Optional dictionary for extra parameters (comment, client-id).
49
+ * @param options Advanced write options.
50
+ * @returns A promise resolving to the API response.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * // Assign a static IP to a new customer's router
55
+ * await mk.ip.addStaticLease(
56
+ * '00:11:22:33:44:55',
57
+ * '192.168.20.50',
58
+ * 'dhcp_lan',
59
+ * { comment: 'Customer: Alice Smith - Plan Basic' }
60
+ * );
61
+ * ```
62
+ */
63
+ async addStaticLease(macAddress, ipAddress, server, additionalParams, options) {
64
+ return this.client.write('/ip/dhcp-server/lease/add', {
65
+ "mac-address": macAddress,
66
+ address: ipAddress,
67
+ server: server,
68
+ ...additionalParams
69
+ }, options);
70
+ }
71
+ /**
72
+ * **Execution Terminator: Delete Lease (REMOVE)**
73
+ *
74
+ * Sends an `/ip/dhcp-server/lease/remove` command to delete a lease.
75
+ *
76
+ * **Feature: Safe Deletion**
77
+ * It automatically searches for the dynamic internal ID (`.id`) using the provided IP
78
+ * before attempting to remove it.
79
+ *
80
+ * @param ipAddress The exact IP address of the lease to remove.
81
+ * @param options Advanced write options.
82
+ * @returns A promise resolving to the API response.
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * // Remove a customer's IP binding after service cancellation
87
+ * try {
88
+ * await mk.ip.removeDhcpLease('192.168.20.50');
89
+ * console.log('Lease removed successfully');
90
+ * } catch (error) {
91
+ * console.error(error.message);
92
+ * }
93
+ * ```
94
+ */
95
+ async removeDhcpLease(ipAddress, options) {
96
+ const result = await this.getDhcpLeases({ "?address": ipAddress }, options);
97
+ if (result.length > 0 && result[0]['.id']) {
98
+ return this.client.write('/ip/dhcp-server/lease/remove', {
99
+ ".id": result[0]['.id']
100
+ }, options);
101
+ }
102
+ throw new Error(`DHCP Lease for IP '${ipAddress}' not found.`);
103
+ }
104
+ // ==========================================
105
+ // ARP (Address Resolution Protocol / Security)
106
+ // ==========================================
107
+ /**
108
+ * **Retrieve: ARP Table (PRINT)**
109
+ *
110
+ * Sends an `/ip/arp/print` command to list current ARP entries.
111
+ *
112
+ * @param filter Optional dictionary to filter results (e.g., searching by interface or IP).
113
+ * @param options Advanced write options.
114
+ * @returns A promise resolving to an array of ARP entries.
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * // Check if a specific IP is reachable at layer 2
119
+ * const arpEntries = await mk.ip.getArpEntries({ "?address": "192.168.20.50" });
120
+ * const isConnected = arpEntries.length > 0;
121
+ * ```
122
+ */
123
+ async getArpEntries(filter, options) {
124
+ return this.client.write('/ip/arp/print', filter || {}, options);
125
+ }
126
+ /**
127
+ * **Resource Creation: Static ARP (ADD)**
128
+ *
129
+ * Sends an `/ip/arp/add` command to create a static layer 2 binding.
130
+ *
131
+ * **Feature: Layer 2 Security**
132
+ * Highly recommended for WISP security to prevent IP spoofing when
133
+ * the router interface is set to `reply-only`.
134
+ *
135
+ * @param macAddress The hardware MAC address of the client.
136
+ * @param ipAddress The exact IP address assigned to the client.
137
+ * @param interfaceName The physical or logical interface facing the client.
138
+ * @param options Advanced write options.
139
+ * @returns A promise resolving to the API response.
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * // Secure a static IP customer by binding their MAC to the interface
144
+ * await mk.ip.addStaticArp(
145
+ * '00:11:22:33:44:55',
146
+ * '192.168.20.50',
147
+ * 'ether3_Clients'
148
+ * );
149
+ * ```
150
+ */
151
+ async addStaticArp(macAddress, ipAddress, interfaceName, options) {
152
+ return this.client.write('/ip/arp/add', {
153
+ "mac-address": macAddress,
154
+ address: ipAddress,
155
+ interface: interfaceName
156
+ }, options);
157
+ }
158
+ /**
159
+ * **Execution Terminator: Delete ARP Entry (REMOVE)**
160
+ *
161
+ * Sends an `/ip/arp/remove` command to delete a static or dynamic ARP entry.
162
+ *
163
+ * @param ipAddress The IP address of the ARP entry to delete.
164
+ * @param options Advanced write options.
165
+ * @returns A promise resolving to the API response.
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * // Clean up the ARP table when a client is permanently disconnected
170
+ * await mk.ip.removeArpEntry('192.168.20.50');
171
+ * ```
172
+ */
173
+ async removeArpEntry(ipAddress, options) {
174
+ const result = await this.getArpEntries({ "?address": ipAddress }, options);
175
+ if (result.length > 0 && result[0]['.id']) {
176
+ return this.client.write('/ip/arp/remove', {
177
+ ".id": result[0]['.id']
178
+ }, options);
179
+ }
180
+ throw new Error(`ARP entry for IP '${ipAddress}' not found.`);
181
+ }
182
+ }
183
+ exports.IpWrapper = IpWrapper;
184
+ //# sourceMappingURL=IpWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IpWrapper.js","sourceRoot":"","sources":["../../src/features/IpWrapper.ts"],"names":[],"mappings":";;;AAEA,MAAa,SAAS;IAGlB,YAAY,MAAsB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED,6CAA6C;IAC7C,qCAAqC;IACrC,6CAA6C;IAE7C;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,KAAK,CAAC,aAAa,CAAC,MAA+B,EAAE,OAAuB;QACxE,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,EAAE,MAAM,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;IACnF,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,KAAK,CAAC,cAAc,CAChB,UAAkB,EAClB,SAAiB,EACjB,MAAc,EACd,gBAA4D,EAC5D,OAAuB;QAEvB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,EAAE;YAClD,aAAa,EAAE,UAAU;YACzB,OAAO,EAAE,SAAS;YAClB,MAAM,EAAE,MAAM;YACd,GAAG,gBAAgB;SACtB,EAAE,OAAO,CAAC,CAAC;IAChB,CAAC;IAED;;;;;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