-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy patharris.py
executable file
·540 lines (491 loc) · 24.3 KB
/
arris.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
#!/usr/bin/python
"""Arris specific SNMP support"""
import enum
import socket
import snmp
class ClientType(snmp.HumaneEnum):
"""Client types in the LanClientTable"""
UNKNOWN = "0"
"No client should use this value"
DYNAMIC = "1"
"""The client IP address is in DHCPv6 or DHCPv6 lease file, but it
is not configured as Reserved client on WebGUI)"""
STATIC = "5"
"""If the client is online, and we can't find the client information
in DHCPv4 or DHCPv6 lease file and it is not configured as
Reserved client on WebGUI, then we put it types to static. Notice
IPv6 stateless client and link local client would also tagged as
this type)
"""
DYNAMIC_RESERVED = "6"
"The Reserved client configured on WebGUI"
# pylint: disable=invalid-name
ClientTypeTranslator = snmp.EnumTranslator(ClientType)
class WanNetworksTable(snmp.Table):
"""List of WAN networks
In some environments, there may be both an IPv6 and IPv6 address
or multiple IPv6 addresses.
The size of this table is usually limited to 4 entries
"""
def __init__(self, transport):
super().__init__(
table_oid="1.3.6.1.4.1.4115.1.20.1.1.1.7.1",
transport=transport,
column_mapping={
"1": dict(name="Index"),
"2": dict(name="addr_type",
translator=snmp.IPVersionTranslator,
doc="Static IP address type"),
"3": dict(name="ipaddr",
translator=snmp.IPAddressTranslator,
doc="Static IP addressfor Wan connection"),
"4": dict(name="prefix",
translator=snmp.IntTranslator,
doc="Netmask (Prefix)"),
"8": dict(name="netmask",
translator=snmp.IPv4Translator,
doc="Netmask if it is IPv4"),
"5": dict(name="gw_ip_type",
translator=snmp.IPVersionTranslator,
doc="Gateway Address type"),
"6": dict(name="gw",
translator=snmp.IPAddressTranslator,
doc="Gateway address"),
# "7": dict(name="iptype",
# translator=snmp.IPVersionTranslator,
# doc="Type of IP address. This appears to be unreliable..."),
"9": dict(name="prefix_delegation",
translator=snmp.IPv6Translator,
doc="The prefix, or initial bits of the address, given "
"to the router to delegate to its attached CPEs"),
"10": dict(name="prefix_delegation_len",
translator=snmp.IntTranslator,
doc="The length for the prefix to be delegated to attached CPEs"),
"11": dict(name="preferredlifetimev6",
translator=snmp.IntTranslator,
doc="The preferred lifetime for the assigned IPv6 address "
"of the router"),
"12": dict(name="validlifetimev6",
translator=snmp.IntTranslator,
doc="The valid lifetime for the assigned IPv6 address "
"of the router")
})
class DNSServerTable(snmp.Table):
"""List of DNS servers known/used by the hub"""
def __init__(self, transport):
super().__init__(
table_oid="1.3.6.1.4.1.4115.1.20.1.1.1.11.2.1",
transport=transport,
column_mapping={
"1": dict(name="index",
translator=snmp.IntTranslator),
"2": dict(name="ip_version",
translator=snmp.IPVersionTranslator),
"3": dict(name="ipaddr",
translator=snmp.IPAddressTranslator)})
class Interfaces(enum.IntFlag):
"""Bitmask for interfaces"""
ETHERNET = 0x00000001
USB = 0x00000002
MOCA = 0x00000004 # apparantly unsupported on TG2492LG-85/10
SSID1 = 0x00000008
SSID2 = 0x00000010
SSID3 = 0x00000020
SSID4 = 0x00000040
SSID5 = 0x00000080
SSID6 = 0x00000100
SSID7 = 0x00000200
SSID8 = 0x00000400
class BitmaskTranslator(snmp.Translator):
"""Translates an SNMP bitmask to/from a python set"""
def __init__(self, enumclass):
self._enumclass = enumclass
def snmp(self, python_value):
if isinstance(python_value, self._enumclass):
return str(python_value.value)
raise TypeError
def pyvalue(self, snmp_value):
return self._enumclass(int(snmp_value))
class LanTable(snmp.Table):
"""Information about the local LAN networks
The router can normally handle more than one network, A single
network can span multiple interfaces.
"""
def __init__(self, transport):
super().__init__(
table_oid="1.3.6.1.4.1.4115.1.20.1.1.2.2.1",
transport=transport,
column_mapping={
"1": dict(name="name"),
"27": dict(name="interfaces",
translator=BitmaskTranslator(Interfaces),
doc="physical network interfaces for this logical network"),
"8": dict(name="vlan",
translator=snmp.IntTranslator,
doc="VLAN ID - use zero for untagged"),
"21": dict(name="passthrough",
doc="""\
Whether or not this Lan is in pass-thru mode or bridged/NAT. To put the device into
non-bridged mode with routing and NAT disabled -- pass-thru, use: passThru(1). To
put the device into bridged (routed) mode with Network Address Translation (NAT)
enabled use: routedNAT(2). To put the device into bridged (routed) mode with
Network Address Translation (NAT) disabled use: routedNoNAT(3)"""),
"4": dict(name="gw_ip_type",
translator=snmp.IPVersionTranslator),
"5": dict(name="gw_ip",
translator=snmp.IPAddressTranslator,
doc="Gateway IP address"),
# "6": dict(name="gw_ip2_type",
# translator=snmp.IPVersionTranslator),
# "7": dict(name="gw_ip2",
# translator=snmp.IPAddressTranslator,
# doc="Second gateway IP address"),
"2": dict(name="subnet_mask_type",
translator=snmp.IPVersionTranslator),
"3": dict(name="subnet_mask",
translator=snmp.IPv4Translator),
"9": dict(name="use_dhcp",
translator=snmp.BoolTranslator,
doc="enable or disable the DHCP server on this LAN"),
"10": dict(name="dhcp_start_ip_type",
translator=snmp.IPVersionTranslator),
"11": dict(name="dhcp_start_ip",
translator=snmp.IPAddressTranslator,
doc="Start of DHCP IP range"),
"12": dict(name="dhcp_end_ip_type",
translator=snmp.IPVersionTranslator),
"13": dict(name="dhcp_end_ip",
translator=snmp.IPAddressTranslator,
doc="End of DHCP IP range"),
"14": dict(name="dhcp_lease_time",
translator=snmp.IntTranslator,
doc="DHCP Lease time in seconds"),
"15": dict(name="domain_name"),
"19": dict(name="dns_relay",
translator=snmp.BoolTranslator),
"25": dict(name="dns_override",
translator=snmp.BoolTranslator,
doc="""\
If DNS override is enabled, the IP addresses in arrisRouterLanDNSTable will be
passed to LAN clients via DHCP. Otherwise, the DNS servers received by the WAN
connection will be passed to the LAN clients."""),
"22": dict(name="firewall",
translator=snmp.BoolTranslator),
"23": dict(name="upnp",
translator=snmp.BoolTranslator),
"24": dict(name="aging_time",
translator=snmp.IntTranslator,
doc="The timeout period in seconds for aging out dynamically " \
"learned forwarding information. " \
"The default value of zero means do not age "),
"39": dict(name="parental_controls",
translator=snmp.BoolTranslator),
"26": dict(name="nat_algs",
doc="""\
Specifies which NAT application layer gateway supplements are enabled on this
device. The default value for this object is for all ALG's to be enabled. Reserved
bits are for ALGs that are currently not supported."""),
"28": dict(name="env_control",
translator=snmp.BoolTranslator,
doc="""\
Controls whether or not the settings which define the operating environment of
the logical interface, aka LAN subnet, are changeable via the GUI. When equal to
unlocked, the environment settings MAY be changed via the UI. When equal to
locked, the environment settings MAY NOT be changed via the UI"""),
})
class LanClientTable(snmp.Table):
"""Information about LAN clients.
This includes both wired and wireless clients.
Retrieving this list can take 10 seconds or more...
"""
def __init__(self, transport):
super().__init__(
table_oid="1.3.6.1.4.1.4115.1.20.1.1.2.4.2.1",
transport=transport,
column_mapping={
"1": dict(name="addrtype",
translator=snmp.IPVersionTranslator),
"2": dict(name="ipaddr",
translator=snmp.IPAddressTranslator),
"3": dict(name="hostname"),
"4": dict(name="mac_address",
translator=snmp.MacAddressTranslator),
# No idea of what 'adapter_type' indicates.... Cannot
# find any documentation on it...
#
# "6": dict(name="adapter_type"),
"7": dict(name="client_type",
translator=ClientTypeTranslator),
"9": dict(name="lease_end",
translator=snmp.DateTimeTranslator),
"13": dict(name="rowstatus",
translator=snmp.RowStatusTranslator),
"14": dict(name="online",
translator=snmp.BoolTranslator),
"15": dict(name="comment"),
# "17": dict(name="manufacturer"),
"18": dict(name="serialno"),
"19": dict(name="product_class"),
"20": dict(name="device_name"),
"24": dict(name="last_change_secs",
translator=snmp.IntTranslator),
"25": dict(name="connected_secs",
translator=snmp.IntTranslator)
})
class EtherPortTable(snmp.Table):
"""The physical ethernet ports
"""
def __init__(self, hub):
super().__init__(table_oid="1.3.6.1.4.1.4115.1.20.1.1.2.8.1",
transport=hub,
column_mapping={
"1": dict(name="idx"),
"2": dict(name="if_index"),
"3": dict(name="enabled",
translator=snmp.BoolTranslator),
"4": dict(name="duplex",
translator=snmp.BoolTranslator),
"5": dict(name="speed_mbps",
translator=snmp.IntTranslator),
"6": dict(name="auto_negotiate",
translator=snmp.BoolTranslator),
"7": dict(name="haslink",
translator=snmp.BoolTranslator)
})
def __delitem__(self, key):
raise NotImplementedError("Deleting physical ethernet ports requires more than just python")
class AccessMode(snmp.HumaneEnum):
"""Defines which wifi clients will be allowed to connect"""
ALLOW_ANY = "1"
WHITELIST = "2"
"""Only stations whose MAC address appears in the
arrisRouterMACAccessTable will be allowed to connect.
"""
BLACKLIST = "3"
"""Only stations whose MAC address do NOT appear in the
arrisRouterMACAccessTable will be allowed to connect.
"""
class BSSTable(snmp.Table):
"""Wifi networks"""
def __init__(self, hub):
super().__init__(table_oid="1.3.6.1.4.1.4115.1.20.1.1.3.22.1",
transport=hub,
column_mapping={
"1": dict(name="mac",
translator=snmp.MacAddressTranslator),
"2": dict(name="ssid"),
"3": dict(name="active",
translator=snmp.BoolTranslator),
"4": dict(name="ssid_broadcast",
translator=snmp.BoolTranslator),
"5": dict(name="security_mode"),
"6": dict(name="access_mode",
translator=snmp.EnumTranslator(AccessMode)),
"7": dict(name="network_isolate",
translator=snmp.BoolTranslator,
doc="when isolated, devices on this network "
"cannot access other local networks"),
# mac_access_count is always zero on TG2492LG-85/10 !?
# Useless.
# "8": dict(name="mac_access_count",
# translator=snmp.IntTranslator),
"10": dict(name="arp_audit_interval",
translator=snmp.IntTranslator),
"11": dict(name="max_wifi_clients",
translator=snmp.IntTranslator),
"12": dict(name="wmm_enable",
translator=snmp.BoolTranslator),
"13": dict(name="wmm_apsd"),
"14": dict(name="active_timeout",
translator=snmp.DateTimeTranslator),
"15": dict(name="default_ssid"),
"16": dict(name="sta_steering",
translator=snmp.BoolTranslator),
})
class WifiClientTable(snmp.Table):
"""Information about the currently connected WIFI clients
"""
def __init__(self, transport):
super().__init__(
table_oid="1.3.6.1.4.1.4115.1.20.1.1.3.42.1",
transport=transport,
column_mapping={
"1": dict(name="index"),
"2": dict(name="ip_version",
translator=snmp.IPVersionTranslator),
"3": dict(name="ipaddr",
translator=snmp.IPAddressTranslator),
"5": dict(name="hostname"),
"6": dict(name="macaddr",
translator=snmp.MacAddressTranslator),
"7": dict(name="manufacturer"),
"8": dict(name="status"),
"9": dict(name="first_seen",
translator=snmp.DateTimeTranslator),
"10": dict(name="last_seen",
translator=snmp.DateTimeTranslator),
# These seem unreliable!? So why bother...
# "11": dict(name="idle_seconds",
# translator=snmp.IntTranslator),
# "12": dict(name="connected_secs",
# translator=snmp.IntTranslator),
"13": dict(name="state"),
"14": dict(name="flags"),
"15": dict(name="tx_packets",
translator=snmp.IntTranslator,
doc="# of packets transmitted from this device "
"since it was connected"),
"16": dict(name="tx_fail",
translator=snmp.IntTranslator,
doc="# of packet xmit failures from this device "
"since it was connected"),
"17": dict(name="rx_unicast_pkts",
translator=snmp.IntTranslator,
doc="# of unicast packets from this device "
"since it was last connected"),
"18": dict(name="rx_multicast_pkts",
translator=snmp.IntTranslator,
doc="# of multicast packets from this device "
"since it was last connected"),
"19": dict(name="last_tx_rate",
translator=snmp.IntTranslator,
doc="Reception rate of the last packet transmitted "
"by this wireless device in kbps/sec"),
"20": dict(name="last_rx_rate",
translator=snmp.IntTranslator,
doc="Reception rate of the last packet received by "
"this wireless device in kbps/sec"),
"21": dict(name="supported_rates",
doc="Supported rate set for this device"),
"22": dict(name="rssi",
translator=snmp.IntTranslator,
doc="Received Signal Strength Indicator - "
"higher values (towards +infinity) are better")
})
class PortForwardTable(snmp.Table):
"""The port forwarding table from the hub
Traffic arriving from the WAN will be forwarded to the internal
servers as per the mapping.
"""
def __init__(self, hub):
super().__init__(table_oid="1.3.6.1.4.1.4115.1.20.1.1.4.12.1",
transport=hub,
column_mapping={
"11": dict(name="rowstatus",
doc="Row status to add/remove rows",
translator=snmp.RowStatusTranslator,
readback_after_write=False),
"5": dict(name="proto",
translator=snmp.IPProtocolTranslator),
"3": dict(name="ext_port_start",
translator=snmp.PortTranslator),
"4": dict(name="ext_port_end",
translator=snmp.PortTranslator),
"6": dict(name="local_addr_type",
translator=snmp.IPVersionTranslator),
"7": dict(name="local_addr",
translator=snmp.IPAddressTranslator),
"9": dict(name="local_port_start",
translator=snmp.PortTranslator),
"10": dict(name="local_port_end",
translator=snmp.PortTranslator)
})
def append(self,
ext_port_start,
ext_port_end=None,
proto=snmp.IPProtocol.TCP,
local_addr_type=snmp.IPVersion.IPv4,
local_addr=None,
local_port_start=None,
local_port_end=None):
"""Add a new (static) port forwarding entry.
"""
if not isinstance(proto, snmp.IPProtocol):
raise TypeError("proto arg to portforward_add must be an IP Protocol"
" - not %s" % proto.__class__)
if not isinstance(ext_port_start, int):
raise TypeError("ext_port_start arg to portforward_add must be an int"
" - not %s" % ext_port_start.__class__)
if local_addr is None:
local_addr = socket.gethostbyname(socket.gethostname())
if local_addr.startswith("127.0."):
raise ValueError("No local_addr passed and unable to find local ip... sorry.")
# TODO: Check types of other parameters?
if ext_port_end is None:
ext_port_end = ext_port_start
if local_port_start is None:
local_port_start = ext_port_start
if local_port_end is None:
local_port_end = ext_port_end
for pfentry in self.values():
if proto.overlaps(pfentry.proto) \
and (pfentry.ext_port_start <= ext_port_start <= pfentry.ext_port_end
or pfentry.ext_port_start <= ext_port_end <= pfentry.ext_port_end) \
and pfentry.rowstatus == snmp.RowStatus.ACTIVE:
raise ValueError("New PortForwardTable entry overlaps with existing ones")
if self.keys():
row_key = str(max(map(int, self.keys()))+1)
else:
row_key = "1"
newrow = self.new_row(
row_key,
rowstatus=snmp.RowStatus.CREATE_AND_WAIT,
proto=proto,
ext_port_start=ext_port_start,
ext_port_end=ext_port_end,
local_addr_type=local_addr_type,
local_addr=local_addr,
local_port_start=local_port_start,
local_port_end=local_port_end
)
newrow.rowstatus = snmp.RowStatus.ACTIVE
class TODStatus(snmp.HumaneEnum):
"""NTP status for the hub"""
NOT_PROVISIONED = "0"
MISSING_SERVER_ADDRESS1 = "1"
MISSING_SERVER_ADDRESS2 = "2"
MISSING_SERVER_ADDRESS3 = "3"
STARTING_REQUEST = "4"
REQUEST_FAILED = "5"
NO_RESPONSE_RECEIVED = "6"
INVALID_DATA_FORMAT = "7"
RETRIEVED = "8"
FAILED = "9"
# pylint: disable=invalid-name
TODStatusTranslator = snmp.EnumTranslator(TODStatus)
class MSOLogTable(snmp.Table):
"""MSO Log
A table of where each row represents an entry in the MSO change
log. This is a log of configuration changes that are not done by
the user. Assumed to be the MSO remotely or a technician.
"""
def __init__(self, transport):
super().__init__(table_oid="1.3.6.1.4.1.4115.1.20.1.1.5.19.2.1.1",
transport=transport,
column_mapping={
"2": dict(name="stamp",
translator=snmp.DateTimeTranslator),
"3": dict(name="text")
})
class FirewallLogTable(snmp.Table):
"""The firewall log.
"""
def __init__(self, transport):
super().__init__(table_oid="1.3.6.1.4.1.4115.1.20.1.1.5.19.1.1.1",
transport=transport,
column_mapping={
"1": dict(name="index",
translator=snmp.IntTranslator),
"2": dict(name="stamp",
translator=snmp.DateTimeTranslator),
"3": dict(name="text")
})
def _run_tests():
import doctest
import sys
fail_count, test_count = doctest.testmod(report=True)
if fail_count:
raise SystemExit("%d out of %d doc tests failed" % (fail_count, test_count))
print("%s: Doc tests were all OK" % sys.argv[0])
if __name__ == "__main__":
_run_tests()