|
1 |
| -# Copyright 2019 Google LLC |
| 1 | +# Copyright 2024 Ryan Benson |
2 | 2 | #
|
3 | 3 | # Licensed under the Apache License, Version 2.0 (the "License");
|
4 | 4 | # you may not use this file except in compliance with the License.
|
|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
15 |
| -import maclookup |
16 |
| -import re |
| 15 | +import mac_vendor_lookup |
17 | 16 | from unfurl import utils
|
18 | 17 |
|
19 | 18 | uuid_edge = {
|
|
26 | 25 |
|
27 | 26 |
|
28 | 27 | def run(unfurl, node):
|
29 |
| - if not node.data_type == 'mac-address': |
| 28 | + if node.data_type == 'mac-address': |
| 29 | + vendor_lookup = mac_vendor_lookup.MacLookup().lookup(node.value) |
| 30 | + if vendor_lookup: |
| 31 | + unfurl.add_to_queue( |
| 32 | + data_type="mac-address.vendor", key=None, value=vendor_lookup, label=f'Vendor: {vendor_lookup}', |
| 33 | + parent_id=node.node_id, incoming_edge_config=uuid_edge) |
| 34 | + |
| 35 | + else: |
30 | 36 | long_int = utils.long_int_re.fullmatch(str(node.value))
|
31 | 37 | m = utils.mac_addr_re.fullmatch(str(node.value))
|
32 | 38 | if m and not long_int:
|
33 | 39 | u = m.group('mac_addr')
|
34 | 40 |
|
35 | 41 | # Check if we need to add colons
|
36 | 42 | if len(u) == 12:
|
37 |
| - pretty_mac = ':'.join([u[i]+u[i+1] for i in range(0, 12, 2)]) |
38 |
| - |
| 43 | + pretty_mac = ':'.join([u[i] + u[i + 1] for i in range(0, 12, 2)]) |
39 | 44 | else:
|
40 | 45 | pretty_mac = u.upper()
|
41 | 46 |
|
42 | 47 | unfurl.add_to_queue(
|
43 | 48 | data_type='mac-address', key=None, value=pretty_mac, label=f'MAC address: {pretty_mac}',
|
44 | 49 | parent_id=node.node_id, incoming_edge_config=uuid_edge)
|
45 |
| - |
46 |
| - elif node.data_type == 'mac-address' and unfurl.api_keys.get('macaddress_io') and unfurl.remote_lookups: |
47 |
| - client = maclookup.ApiClient(unfurl.api_keys.get('macaddress_io')) |
48 |
| - vendor_lookup = client.get_vendor(node.value).decode('utf-8') |
49 |
| - |
50 |
| - if vendor_lookup: |
51 |
| - unfurl.add_to_queue( |
52 |
| - data_type="mac-address.vendor", key=None, value=vendor_lookup, label=f'Vendor: {vendor_lookup}', |
53 |
| - parent_id=node.node_id, incoming_edge_config=uuid_edge) |
0 commit comments