etherlyzer 0.9.7__tar.gz → 0.9.8__tar.gz
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.
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/PKG-INFO +1 -1
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/pyproject.toml +1 -1
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/formatters.py +3 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/ieee/entry/mac.py +30 -0
- etherlyzer-0.9.8/src/etherlyzer/ieee/index/base.py +13 -0
- etherlyzer-0.9.8/src/etherlyzer/ieee/index/ethertype.py +22 -0
- etherlyzer-0.9.8/src/etherlyzer/ieee/index/identifier.py +32 -0
- etherlyzer-0.9.8/src/etherlyzer/ieee/index/ieee_index.py +105 -0
- etherlyzer-0.9.8/src/etherlyzer/ieee/index/mac_allocation.py +43 -0
- etherlyzer-0.9.8/src/etherlyzer/ieee/index/vendor.py +38 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/ieee/registry/catalog.py +5 -2
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/ieee/registry/category.py +1 -1
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/ieee/registry/ieee_registry.py +2 -1
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/terminal/commands/format.py +25 -1
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/terminal/commands/inspect/controller.py +5 -3
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/terminal/commands/inspect/types/display.py +4 -4
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/terminal/commands/inspect/types/ethertype_inspection.py +2 -2
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/terminal/commands/inspect/types/mac_inspection.py +16 -13
- etherlyzer-0.9.8/src/etherlyzer/terminal/commands/registries.py +74 -0
- etherlyzer-0.9.8/src/etherlyzer/terminal/commands/sync.py +89 -0
- etherlyzer-0.9.8/src/etherlyzer/terminal/commands/whois.py +157 -0
- etherlyzer-0.9.8/src/etherlyzer/terminal/utility.py +43 -0
- etherlyzer-0.9.8/src/etherlyzer/util/__init__.py +0 -0
- etherlyzer-0.9.8/src/etherlyzer/util/conversion.py +0 -0
- etherlyzer-0.9.7/src/etherlyzer/ieee/registry/index.py +0 -217
- etherlyzer-0.9.7/src/etherlyzer/terminal/commands/registries.py +0 -55
- etherlyzer-0.9.7/src/etherlyzer/terminal/commands/sync.py +0 -35
- etherlyzer-0.9.7/src/etherlyzer/terminal/commands/whois.py +0 -88
- etherlyzer-0.9.7/src/etherlyzer/terminal/utility.py +0 -20
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/LICENSE +0 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/README.md +0 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/__init__.py +0 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/etherlyzer.env +0 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/exporter.py +0 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/ieee/__init__.py +0 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/ieee/analytics/__init__.py +0 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/ieee/analytics/allocations.py +0 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/ieee/analytics/mac_classification.py +0 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/ieee/entry/__init__.py +0 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/ieee/entry/base.py +0 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/ieee/entry/ethertype.py +0 -0
- {etherlyzer-0.9.7/src/etherlyzer/ieee/registry → etherlyzer-0.9.8/src/etherlyzer/ieee/index}/__init__.py +0 -0
- /etherlyzer-0.9.7/src/etherlyzer/py.typed → /etherlyzer-0.9.8/src/etherlyzer/ieee/index/utils.py +0 -0
- {etherlyzer-0.9.7/src/etherlyzer/terminal → etherlyzer-0.9.8/src/etherlyzer/ieee/registry}/__init__.py +0 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/ieee/registry/cache.py +0 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/ieee/registry/downloader.py +0 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/ieee/registry/parser.py +0 -0
- /etherlyzer-0.9.7/src/etherlyzer/terminal/commands/inspect/__init__.py → /etherlyzer-0.9.8/src/etherlyzer/py.typed +0 -0
- {etherlyzer-0.9.7/src/etherlyzer/terminal/commands/inspect/types → etherlyzer-0.9.8/src/etherlyzer/terminal}/__init__.py +0 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/terminal/cli.py +0 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/terminal/commands/__init__.py +0 -0
- {etherlyzer-0.9.7/src/etherlyzer/util → etherlyzer-0.9.8/src/etherlyzer/terminal/commands/inspect}/__init__.py +0 -0
- /etherlyzer-0.9.7/src/etherlyzer/util/conversion.py → /etherlyzer-0.9.8/src/etherlyzer/terminal/commands/inspect/types/__init__.py +0 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/terminal/commands/inspect/validation.py +0 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/terminal/commands/validate.py +0 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/util/dirs.py +0 -0
- {etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/util/knobs.py +0 -0
|
@@ -42,6 +42,7 @@ class MACFormatter:
|
|
|
42
42
|
|
|
43
43
|
@classmethod
|
|
44
44
|
def format_default(cls, mac: str) -> str:
|
|
45
|
+
"""Formats a MAC address according to how etherlyze_knobs is configured ."""
|
|
45
46
|
mac = cls.normalize(mac)
|
|
46
47
|
mac = etherlyzer_knobs.mac_separator.join(
|
|
47
48
|
mac[i : i + etherlyzer_knobs.mac_block_size]
|
|
@@ -52,6 +53,7 @@ class MACFormatter:
|
|
|
52
53
|
|
|
53
54
|
@classmethod
|
|
54
55
|
def format_with_stuffed_hex(cls, mac: str, stuffed_hex: str) -> str:
|
|
56
|
+
"""Pad with extra hex-decimals"""
|
|
55
57
|
mac = (cls.normalize(mac) + 12 * stuffed_hex)[:12]
|
|
56
58
|
return cls.format_default(mac)
|
|
57
59
|
|
|
@@ -64,6 +66,7 @@ class MACFormatter:
|
|
|
64
66
|
case: Literal["upper", "lower"],
|
|
65
67
|
fix_typos: bool = False,
|
|
66
68
|
) -> str:
|
|
69
|
+
"""Custom MAC address formatting"""
|
|
67
70
|
if fix_typos:
|
|
68
71
|
mac = cls.fix_typos(mac)
|
|
69
72
|
mac = cls.normalize(mac)
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import re
|
|
2
|
+
import string
|
|
2
3
|
from dataclasses import dataclass
|
|
3
4
|
|
|
5
|
+
from etherlyzer.formatters import MACFormatter
|
|
4
6
|
from etherlyzer.ieee.entry.base import BaseEntry
|
|
5
7
|
|
|
6
8
|
|
|
@@ -28,3 +30,31 @@ class MACAllocationEntry(BaseEntry):
|
|
|
28
30
|
if line:
|
|
29
31
|
addr_representation.append(line.strip())
|
|
30
32
|
return addr_representation
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass(frozen=True, slots=True)
|
|
36
|
+
class MACLookupResult:
|
|
37
|
+
line_number: int
|
|
38
|
+
mac: str
|
|
39
|
+
entry: MACAllocationEntry | None = None
|
|
40
|
+
reason: str | None = None
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def classify_mac(mac: str) -> str | None:
|
|
44
|
+
normalized = MACFormatter.normalize(mac)
|
|
45
|
+
|
|
46
|
+
if len(normalized) != 12 or any(c not in string.hexdigits for c in normalized):
|
|
47
|
+
return "Invalid format"
|
|
48
|
+
|
|
49
|
+
first_octet = int(normalized[:2], 16)
|
|
50
|
+
|
|
51
|
+
is_group = bool(first_octet & 0x01)
|
|
52
|
+
is_local = bool(first_octet & 0x02)
|
|
53
|
+
|
|
54
|
+
if not (is_group or is_local):
|
|
55
|
+
return None
|
|
56
|
+
|
|
57
|
+
administration = "Local" if is_local else "Universal"
|
|
58
|
+
delivery = "Multicast" if is_group else "Unicast"
|
|
59
|
+
|
|
60
|
+
return f"{administration} {delivery}"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Protocol
|
|
4
|
+
|
|
5
|
+
from etherlyzer.ieee.entry.ethertype import EtherTypeEntry
|
|
6
|
+
from etherlyzer.ieee.entry.mac import MACAllocationEntry
|
|
7
|
+
|
|
8
|
+
HEX_DIGITS = frozenset("0123456789ABCDEF")
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class IEEEIndexProtocol(Protocol):
|
|
12
|
+
def get_many(self, identifier: str) -> list[MACAllocationEntry | EtherTypeEntry] | None: ...
|
|
13
|
+
def get_one(self, identifier: str) -> MACAllocationEntry | EtherTypeEntry | None: ...
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Iterable
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
|
|
6
|
+
from etherlyzer.ieee.entry.ethertype import EtherTypeEntry
|
|
7
|
+
from etherlyzer.ieee.index.base import HEX_DIGITS, IEEEIndexProtocol
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(slots=True)
|
|
11
|
+
class EthertypeIndex(IEEEIndexProtocol):
|
|
12
|
+
ethertype: dict[str, EtherTypeEntry] = field(default_factory=dict)
|
|
13
|
+
|
|
14
|
+
def insert(
|
|
15
|
+
self,
|
|
16
|
+
entries: Iterable[EtherTypeEntry],
|
|
17
|
+
) -> None:
|
|
18
|
+
self.ethertype.update({entry.assignment.upper(): entry for entry in entries})
|
|
19
|
+
|
|
20
|
+
def get_one(self, identifier: str) -> EtherTypeEntry | None:
|
|
21
|
+
ethertype = "".join(c for c in identifier.upper() if c in HEX_DIGITS)
|
|
22
|
+
return self.ethertype.get(ethertype)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Iterable
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
|
|
6
|
+
from etherlyzer.ieee.entry.mac import MACAllocationEntry
|
|
7
|
+
from etherlyzer.ieee.index.base import IEEEIndexProtocol
|
|
8
|
+
from etherlyzer.ieee.registry.ieee_registry import IEEERegistry
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(slots=True)
|
|
12
|
+
class IdentifierIndex(IEEEIndexProtocol):
|
|
13
|
+
cid: dict[str, MACAllocationEntry] = field(default_factory=dict)
|
|
14
|
+
opid: dict[str, MACAllocationEntry] = field(default_factory=dict)
|
|
15
|
+
manid: dict[str, MACAllocationEntry] = field(default_factory=dict)
|
|
16
|
+
|
|
17
|
+
def insert(self, registry: IEEERegistry, entries: Iterable[MACAllocationEntry]) -> None:
|
|
18
|
+
match registry.name:
|
|
19
|
+
case "CID":
|
|
20
|
+
target = self.cid
|
|
21
|
+
case "OPID":
|
|
22
|
+
target = self.opid
|
|
23
|
+
case "MANID":
|
|
24
|
+
target = self.manid
|
|
25
|
+
case _:
|
|
26
|
+
raise ValueError(f"Unsupported identifier registry: {registry.name}")
|
|
27
|
+
|
|
28
|
+
target.update({entry.assignment.upper(): entry for entry in entries})
|
|
29
|
+
|
|
30
|
+
def get_one(self, identifier: str) -> MACAllocationEntry | None:
|
|
31
|
+
identifier = identifier.upper()
|
|
32
|
+
return self.cid.get(identifier) or self.opid.get(identifier) or self.manid.get(identifier)
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Iterable
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
|
|
6
|
+
from etherlyzer.ieee.entry.ethertype import EtherTypeEntry
|
|
7
|
+
from etherlyzer.ieee.entry.mac import MACAllocationEntry, MACLookupResult, classify_mac
|
|
8
|
+
from etherlyzer.ieee.index.ethertype import EthertypeIndex
|
|
9
|
+
from etherlyzer.ieee.index.identifier import IdentifierIndex
|
|
10
|
+
from etherlyzer.ieee.index.mac_allocation import MACAllocationIndex
|
|
11
|
+
from etherlyzer.ieee.index.vendor import VendorIndex
|
|
12
|
+
from etherlyzer.ieee.registry.category import RegistryCategory
|
|
13
|
+
from etherlyzer.ieee.registry.ieee_registry import IEEERegistry
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass(slots=True)
|
|
17
|
+
class IEEEIndexCatalog:
|
|
18
|
+
mac_index: MACAllocationIndex = field(default_factory=MACAllocationIndex)
|
|
19
|
+
ethertype_index: EthertypeIndex = field(default_factory=EthertypeIndex)
|
|
20
|
+
identifier_index: IdentifierIndex = field(default_factory=IdentifierIndex)
|
|
21
|
+
vendor_index: VendorIndex = field(default_factory=VendorIndex)
|
|
22
|
+
|
|
23
|
+
@classmethod
|
|
24
|
+
def build(cls, registries: Iterable[IEEERegistry]) -> IEEEIndexCatalog:
|
|
25
|
+
index = cls()
|
|
26
|
+
|
|
27
|
+
for registry in registries:
|
|
28
|
+
index._ingest(registry)
|
|
29
|
+
|
|
30
|
+
index._build_vendor_index()
|
|
31
|
+
return index
|
|
32
|
+
|
|
33
|
+
def _ingest(self, registry: IEEERegistry) -> None:
|
|
34
|
+
entries = registry.load()
|
|
35
|
+
|
|
36
|
+
match registry.category:
|
|
37
|
+
case RegistryCategory.MAC_REGISTRY:
|
|
38
|
+
self.mac_index.insert(registry, entries)
|
|
39
|
+
case RegistryCategory.ETHERTYPE_REGISTRY:
|
|
40
|
+
self.ethertype_index.insert(entries)
|
|
41
|
+
case RegistryCategory.IDENTIFIER_REGISTRY:
|
|
42
|
+
self.identifier_index.insert(registry, entries)
|
|
43
|
+
case _:
|
|
44
|
+
raise ValueError(f"Unsupported registry category: {registry.category}")
|
|
45
|
+
|
|
46
|
+
def _build_vendor_index(self) -> None:
|
|
47
|
+
for mac in self.mac_index.walk():
|
|
48
|
+
entry = self.mac_index.get_one(mac)
|
|
49
|
+
if entry is not None:
|
|
50
|
+
self.vendor_index.insert(entry)
|
|
51
|
+
|
|
52
|
+
def get_from_mac_index(self, mac: str) -> MACAllocationEntry | None:
|
|
53
|
+
return self.mac_index.get_one(mac)
|
|
54
|
+
|
|
55
|
+
def get_from_ethertype_index(self, ethertype: str) -> EtherTypeEntry | None:
|
|
56
|
+
ret = self.ethertype_index.get_one(ethertype)
|
|
57
|
+
if not isinstance(ret, EtherTypeEntry) and not isinstance(ret, type(None)):
|
|
58
|
+
raise RuntimeError()
|
|
59
|
+
return ret
|
|
60
|
+
|
|
61
|
+
def get_from_identifier_index(self, identifier: str) -> MACAllocationEntry | None:
|
|
62
|
+
return self.identifier_index.get_one(identifier)
|
|
63
|
+
|
|
64
|
+
@staticmethod
|
|
65
|
+
def get_bulk(
|
|
66
|
+
ieee_index: MACAllocationIndex,
|
|
67
|
+
values: Iterable[str],
|
|
68
|
+
include_unsuccessful: bool = False,
|
|
69
|
+
) -> list[MACLookupResult]:
|
|
70
|
+
results = []
|
|
71
|
+
|
|
72
|
+
for line_number, mac in enumerate(values, start=1):
|
|
73
|
+
mac = mac.strip()
|
|
74
|
+
reason = classify_mac(mac)
|
|
75
|
+
|
|
76
|
+
if reason is not None:
|
|
77
|
+
result = MACLookupResult(
|
|
78
|
+
line_number=line_number,
|
|
79
|
+
mac=mac,
|
|
80
|
+
reason=reason,
|
|
81
|
+
)
|
|
82
|
+
else:
|
|
83
|
+
entry = ieee_index.get_one(mac)
|
|
84
|
+
|
|
85
|
+
result = MACLookupResult(
|
|
86
|
+
line_number=line_number,
|
|
87
|
+
mac=mac,
|
|
88
|
+
entry=entry,
|
|
89
|
+
reason=None if entry is not None else "Not found",
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
if result.entry is not None or include_unsuccessful:
|
|
93
|
+
results.append(result)
|
|
94
|
+
|
|
95
|
+
return results
|
|
96
|
+
|
|
97
|
+
@staticmethod
|
|
98
|
+
def get_single(
|
|
99
|
+
indextype: VendorIndex | MACAllocationIndex | IdentifierIndex | EthertypeIndex, mac: str
|
|
100
|
+
) -> MACAllocationEntry | list[MACAllocationEntry] | None:
|
|
101
|
+
ieee_entry = indextype.get_one(mac)
|
|
102
|
+
if ieee_entry:
|
|
103
|
+
return ieee_entry
|
|
104
|
+
else:
|
|
105
|
+
return None
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Generator, Iterable
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
|
|
6
|
+
from etherlyzer.ieee.entry.mac import MACAllocationEntry
|
|
7
|
+
from etherlyzer.ieee.index.base import HEX_DIGITS, IEEEIndexProtocol
|
|
8
|
+
from etherlyzer.ieee.registry.ieee_registry import IEEERegistry
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(slots=True)
|
|
12
|
+
class MACAllocationIndex(IEEEIndexProtocol):
|
|
13
|
+
prefixes_36: dict[str, MACAllocationEntry] = field(default_factory=dict)
|
|
14
|
+
prefixes_28: dict[str, MACAllocationEntry] = field(default_factory=dict)
|
|
15
|
+
prefixes_24: dict[str, MACAllocationEntry] = field(default_factory=dict)
|
|
16
|
+
|
|
17
|
+
def insert(self, registry: IEEERegistry, entries: Iterable[MACAllocationEntry]) -> None:
|
|
18
|
+
match registry.prefix_bits:
|
|
19
|
+
case 36:
|
|
20
|
+
target = self.prefixes_36
|
|
21
|
+
case 28:
|
|
22
|
+
target = self.prefixes_28
|
|
23
|
+
case 24:
|
|
24
|
+
target = self.prefixes_24
|
|
25
|
+
case _:
|
|
26
|
+
raise ValueError(f"Unsupported prefix length: {registry.prefix_bits}")
|
|
27
|
+
|
|
28
|
+
target.update({entry.assignment.upper(): entry for entry in entries})
|
|
29
|
+
|
|
30
|
+
def get_one(self, identifier: str) -> MACAllocationEntry | None:
|
|
31
|
+
mac = "".join(c for c in identifier.upper() if c in HEX_DIGITS)
|
|
32
|
+
|
|
33
|
+
# longest prefix match
|
|
34
|
+
return (
|
|
35
|
+
self.prefixes_36.get(mac[:9])
|
|
36
|
+
or self.prefixes_28.get(mac[:7])
|
|
37
|
+
or self.prefixes_24.get(mac[:6])
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
def walk(self) -> Generator[str]:
|
|
41
|
+
yield from self.prefixes_36
|
|
42
|
+
yield from self.prefixes_28
|
|
43
|
+
yield from self.prefixes_24
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
|
|
6
|
+
from etherlyzer.ieee.entry.mac import MACAllocationEntry
|
|
7
|
+
from etherlyzer.ieee.index.base import IEEEIndexProtocol
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def normalize_vendor_name(name: str) -> str:
|
|
11
|
+
name = name.casefold()
|
|
12
|
+
name = re.sub(r"[.,/\\()\-_'\"&]+", " ", name)
|
|
13
|
+
name = re.sub(r"\s+", " ", name)
|
|
14
|
+
return name.strip()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass(slots=True)
|
|
18
|
+
class VendorIndex(IEEEIndexProtocol):
|
|
19
|
+
vendors: dict[str, list[MACAllocationEntry]] = field(default_factory=dict)
|
|
20
|
+
|
|
21
|
+
def insert(self, entry: MACAllocationEntry) -> None:
|
|
22
|
+
key = normalize_vendor_name(
|
|
23
|
+
entry.organization_name,
|
|
24
|
+
)
|
|
25
|
+
self.vendors.setdefault(key, []).append(entry)
|
|
26
|
+
|
|
27
|
+
def get_many(self, identifier: str) -> list[MACAllocationEntry] | None:
|
|
28
|
+
ieee_mac_entries = self.vendors.get(
|
|
29
|
+
normalize_vendor_name(identifier),
|
|
30
|
+
)
|
|
31
|
+
if ieee_mac_entries is not None:
|
|
32
|
+
ieee_mac_entries.sort(
|
|
33
|
+
key=lambda entry: int(
|
|
34
|
+
"".join(c for c in entry.assignment if c in "0123456789ABCDEFabcdef"),
|
|
35
|
+
16,
|
|
36
|
+
)
|
|
37
|
+
)
|
|
38
|
+
return ieee_mac_entries
|
|
@@ -97,7 +97,7 @@ class Catalog:
|
|
|
97
97
|
model=EtherTypeEntry,
|
|
98
98
|
full_name="EtherType Registry",
|
|
99
99
|
legacy_name=None,
|
|
100
|
-
category=RegistryCategory.
|
|
100
|
+
category=RegistryCategory.ETHERTYPE_REGISTRY,
|
|
101
101
|
legacy=False,
|
|
102
102
|
description=(
|
|
103
103
|
"Registry mapping EtherType values to Ethernet protocols, "
|
|
@@ -122,7 +122,7 @@ class Catalog:
|
|
|
122
122
|
raise RuntimeError(f"Unknown registry {registry_name}")
|
|
123
123
|
return reg
|
|
124
124
|
|
|
125
|
-
def
|
|
125
|
+
def get_all_registries_and_ensure_cache_is_synced(
|
|
126
126
|
self, check_for_updates: bool = True, inform_if_synced_about_expiration: bool = False
|
|
127
127
|
) -> list[IEEERegistry]:
|
|
128
128
|
for registry in self.IEEE_REGISTRIES.values():
|
|
@@ -136,5 +136,8 @@ class Catalog:
|
|
|
136
136
|
break
|
|
137
137
|
return list(self.IEEE_REGISTRIES.values())
|
|
138
138
|
|
|
139
|
+
def get_registries(self) -> list[IEEERegistry]:
|
|
140
|
+
return list(self.IEEE_REGISTRIES.values())
|
|
141
|
+
|
|
139
142
|
def __getitem__(self, key: str) -> IEEERegistry:
|
|
140
143
|
return self.IEEE_REGISTRIES[key]
|
|
@@ -40,6 +40,7 @@ class IEEERegistry[T]:
|
|
|
40
40
|
)
|
|
41
41
|
|
|
42
42
|
def load(self) -> list[T]:
|
|
43
|
+
"""Fetch if self.filepath not exists, else parse and build self.filepath into self.model objects."""
|
|
43
44
|
if not self.registry_cache.filepath.exists():
|
|
44
45
|
self.registry_downloader.fetch_online()
|
|
45
46
|
return self.registry_parser.load_file(self.registry_cache.filepath, self.model)
|
|
@@ -50,7 +51,7 @@ class IEEERegistry[T]:
|
|
|
50
51
|
|
|
51
52
|
@property
|
|
52
53
|
def is_protocol_registry(self) -> bool:
|
|
53
|
-
return self.category is RegistryCategory.
|
|
54
|
+
return self.category is RegistryCategory.ETHERTYPE_REGISTRY
|
|
54
55
|
|
|
55
56
|
@property
|
|
56
57
|
def is_identifier_registry(self) -> bool:
|
|
@@ -7,8 +7,26 @@ from etherlyzer.terminal.utility import read_multiline
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
def run(args: argparse.Namespace) -> int:
|
|
10
|
-
|
|
10
|
+
if args.linenumbers and not args.bulk:
|
|
11
|
+
raise argparse.ArgumentError(None, "--linenumbers requires --bulk")
|
|
12
|
+
linenumber = 0
|
|
13
|
+
|
|
14
|
+
macs = (
|
|
15
|
+
read_multiline(linetype="MAC addresses", skip_empty_lines=False)
|
|
16
|
+
if args.bulk
|
|
17
|
+
else [args.mac]
|
|
18
|
+
)
|
|
19
|
+
padding = (
|
|
20
|
+
len(
|
|
21
|
+
str(len(macs)),
|
|
22
|
+
)
|
|
23
|
+
+ 2
|
|
24
|
+
) # Decimal count + spacing
|
|
25
|
+
|
|
11
26
|
for mac in macs:
|
|
27
|
+
if args.linenumbers:
|
|
28
|
+
linenumber += 1
|
|
29
|
+
print(f"{linenumber}.".ljust(padding, " "), end="")
|
|
12
30
|
print(
|
|
13
31
|
MACFormatter.format_custom(
|
|
14
32
|
mac=mac,
|
|
@@ -57,6 +75,12 @@ Examples:
|
|
|
57
75
|
action="store_true",
|
|
58
76
|
help="Read multiple MAC addresses interactively.",
|
|
59
77
|
)
|
|
78
|
+
parser.add_argument(
|
|
79
|
+
"-l",
|
|
80
|
+
"--linenumbers",
|
|
81
|
+
action="store_true",
|
|
82
|
+
help="Prefix output lines with their corresponding input line number.",
|
|
83
|
+
)
|
|
60
84
|
|
|
61
85
|
parser.add_argument(
|
|
62
86
|
"-p",
|
{etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/terminal/commands/inspect/controller.py
RENAMED
|
@@ -5,9 +5,9 @@ from dataclasses import dataclass
|
|
|
5
5
|
|
|
6
6
|
from etherlyzer.formatters import MACFormatter
|
|
7
7
|
from etherlyzer.ieee.analytics.mac_classification import classify_mac
|
|
8
|
+
from etherlyzer.ieee.index.ieee_index import IEEEIndexCatalog
|
|
8
9
|
from etherlyzer.ieee.registry.catalog import Catalog
|
|
9
10
|
from etherlyzer.ieee.registry.category import RegistryCategory
|
|
10
|
-
from etherlyzer.ieee.registry.index import IEEEIndex
|
|
11
11
|
from etherlyzer.terminal.commands.inspect.types.display import show_cid_registration
|
|
12
12
|
from etherlyzer.terminal.commands.inspect.types.ethertype_inspection import inspect_ethertype
|
|
13
13
|
from etherlyzer.terminal.commands.inspect.types.mac_inspection import inspect_ieee_quadrants
|
|
@@ -25,7 +25,9 @@ def run(args: argparse.Namespace) -> int:
|
|
|
25
25
|
validate_args(args)
|
|
26
26
|
|
|
27
27
|
registry = Catalog()
|
|
28
|
-
index =
|
|
28
|
+
index = IEEEIndexCatalog.build(
|
|
29
|
+
registry.get_all_registries_and_ensure_cache_is_synced(check_for_updates=False)
|
|
30
|
+
)
|
|
29
31
|
eval_flags = EvaluatedFlags(
|
|
30
32
|
show_mac_autopsy=args.all or args.show_mac_autopsy,
|
|
31
33
|
show_vendor_stats=(args.all or args.show_vendor_stats or args.show_vendor_blocks),
|
|
@@ -35,7 +37,7 @@ def run(args: argparse.Namespace) -> int:
|
|
|
35
37
|
match args.type.lower():
|
|
36
38
|
case RegistryCategory.MAC_REGISTRY.value:
|
|
37
39
|
return inspect_ieee_quadrants(args, index, eval_flags)
|
|
38
|
-
case RegistryCategory.
|
|
40
|
+
case RegistryCategory.ETHERTYPE_REGISTRY.value:
|
|
39
41
|
entry = index.get_single(index.protocol_index, args.value)
|
|
40
42
|
inspect_ethertype(args, entry, index)
|
|
41
43
|
case RegistryCategory.IDENTIFIER_REGISTRY.value:
|
{etherlyzer-0.9.7 → etherlyzer-0.9.8}/src/etherlyzer/terminal/commands/inspect/types/display.py
RENAMED
|
@@ -12,8 +12,8 @@ from etherlyzer.ieee.analytics.mac_classification import (
|
|
|
12
12
|
SLAPQuadrant,
|
|
13
13
|
)
|
|
14
14
|
from etherlyzer.ieee.entry.mac import MACAllocationEntry
|
|
15
|
+
from etherlyzer.ieee.index.ieee_index import IEEEIndexCatalog
|
|
15
16
|
from etherlyzer.ieee.registry.ieee_registry import IEEERegistry
|
|
16
|
-
from etherlyzer.ieee.registry.index import IEEEIndex
|
|
17
17
|
|
|
18
18
|
if TYPE_CHECKING:
|
|
19
19
|
from etherlyzer.terminal.commands.inspect.controller import EvaluatedFlags
|
|
@@ -88,7 +88,7 @@ def display_organization(entry: MACAllocationEntry, short_orgname: str) -> None:
|
|
|
88
88
|
|
|
89
89
|
def display_ieee_identifier(
|
|
90
90
|
args: argparse.Namespace,
|
|
91
|
-
index:
|
|
91
|
+
index: IEEEIndexCatalog,
|
|
92
92
|
eval_flags: EvaluatedFlags,
|
|
93
93
|
classified_mac: MACClassification,
|
|
94
94
|
) -> None:
|
|
@@ -165,7 +165,7 @@ def display_ieee_identifier(
|
|
|
165
165
|
|
|
166
166
|
def display_mac_autopsy(
|
|
167
167
|
args: argparse.Namespace,
|
|
168
|
-
index:
|
|
168
|
+
index: IEEEIndexCatalog,
|
|
169
169
|
eval_flags: EvaluatedFlags,
|
|
170
170
|
classified_mac: MACClassification,
|
|
171
171
|
) -> None:
|
|
@@ -216,7 +216,7 @@ def display_mac_autopsy(
|
|
|
216
216
|
print(f" I/G : {ig_bit} {ig_bit_addon}")
|
|
217
217
|
|
|
218
218
|
|
|
219
|
-
def show_cid_registration(index:
|
|
219
|
+
def show_cid_registration(index: IEEEIndexCatalog, normalized: str, slap: SLAPQuadrant) -> None:
|
|
220
220
|
cid_length = 6
|
|
221
221
|
if slap == SLAPQuadrant.ELI:
|
|
222
222
|
cid_entry = index.get_single(indextype=index.identifier_index, mac=normalized[:cid_length])
|
|
@@ -2,11 +2,11 @@ import argparse
|
|
|
2
2
|
|
|
3
3
|
from etherlyzer.ieee.entry.ethertype import EtherTypeEntry
|
|
4
4
|
from etherlyzer.ieee.entry.mac import MACAllocationEntry
|
|
5
|
-
from etherlyzer.ieee.
|
|
5
|
+
from etherlyzer.ieee.index.ieee_index import IEEEIndexCatalog
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
def inspect_ethertype(
|
|
9
|
-
args: argparse.Namespace, entry: MACAllocationEntry, index:
|
|
9
|
+
args: argparse.Namespace, entry: MACAllocationEntry, index: IEEEIndexCatalog
|
|
10
10
|
) -> None:
|
|
11
11
|
if isinstance(entry, EtherTypeEntry):
|
|
12
12
|
print(f" Protocol : {entry.protocol}")
|
|
@@ -10,8 +10,8 @@ from etherlyzer.ieee.analytics.mac_classification import (
|
|
|
10
10
|
SLAPQuadrant,
|
|
11
11
|
classify_mac,
|
|
12
12
|
)
|
|
13
|
+
from etherlyzer.ieee.index.ieee_index import IEEEIndexCatalog
|
|
13
14
|
from etherlyzer.ieee.registry.catalog import Catalog
|
|
14
|
-
from etherlyzer.ieee.registry.index import IEEEIndex
|
|
15
15
|
|
|
16
16
|
if TYPE_CHECKING:
|
|
17
17
|
from etherlyzer.terminal.commands.inspect.controller import EvaluatedFlags
|
|
@@ -27,14 +27,14 @@ from etherlyzer.terminal.commands.inspect.types.display import (
|
|
|
27
27
|
|
|
28
28
|
class InspectionParams(TypedDict):
|
|
29
29
|
args: argparse.Namespace
|
|
30
|
-
index:
|
|
30
|
+
index: IEEEIndexCatalog
|
|
31
31
|
eval_flags: EvaluatedFlags
|
|
32
32
|
classified_mac: MACClassification
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
def inspect_universal_individual(
|
|
36
36
|
args: argparse.Namespace,
|
|
37
|
-
index:
|
|
37
|
+
index: IEEEIndexCatalog,
|
|
38
38
|
eval_flags: EvaluatedFlags,
|
|
39
39
|
classified_mac: MACClassification,
|
|
40
40
|
) -> bool | None:
|
|
@@ -68,7 +68,7 @@ def inspect_universal_individual(
|
|
|
68
68
|
|
|
69
69
|
def inspect_universal_group(
|
|
70
70
|
args: argparse.Namespace,
|
|
71
|
-
index:
|
|
71
|
+
index: IEEEIndexCatalog,
|
|
72
72
|
eval_flags: EvaluatedFlags,
|
|
73
73
|
classified_mac: MACClassification,
|
|
74
74
|
) -> None:
|
|
@@ -77,7 +77,7 @@ def inspect_universal_group(
|
|
|
77
77
|
|
|
78
78
|
def inspect_local_individual(
|
|
79
79
|
args: argparse.Namespace,
|
|
80
|
-
index:
|
|
80
|
+
index: IEEEIndexCatalog,
|
|
81
81
|
eval_flags: EvaluatedFlags,
|
|
82
82
|
classified_mac: MACClassification,
|
|
83
83
|
) -> None:
|
|
@@ -108,7 +108,7 @@ def inspect_local_individual(
|
|
|
108
108
|
|
|
109
109
|
def inspect_local_individual_eli(
|
|
110
110
|
args: argparse.Namespace,
|
|
111
|
-
index:
|
|
111
|
+
index: IEEEIndexCatalog,
|
|
112
112
|
eval_flags: EvaluatedFlags,
|
|
113
113
|
classified_mac: MACClassification,
|
|
114
114
|
) -> None:
|
|
@@ -117,7 +117,7 @@ def inspect_local_individual_eli(
|
|
|
117
117
|
|
|
118
118
|
def inspect_local_individual_reserved(
|
|
119
119
|
args: argparse.Namespace,
|
|
120
|
-
index:
|
|
120
|
+
index: IEEEIndexCatalog,
|
|
121
121
|
eval_flags: EvaluatedFlags,
|
|
122
122
|
classified_mac: MACClassification,
|
|
123
123
|
) -> None:
|
|
@@ -126,7 +126,7 @@ def inspect_local_individual_reserved(
|
|
|
126
126
|
|
|
127
127
|
def inspect_local_individual_sai(
|
|
128
128
|
args: argparse.Namespace,
|
|
129
|
-
index:
|
|
129
|
+
index: IEEEIndexCatalog,
|
|
130
130
|
eval_flags: EvaluatedFlags,
|
|
131
131
|
classified_mac: MACClassification,
|
|
132
132
|
) -> None:
|
|
@@ -135,7 +135,7 @@ def inspect_local_individual_sai(
|
|
|
135
135
|
|
|
136
136
|
def inspect_local_individual_aai(
|
|
137
137
|
args: argparse.Namespace,
|
|
138
|
-
index:
|
|
138
|
+
index: IEEEIndexCatalog,
|
|
139
139
|
eval_flags: EvaluatedFlags,
|
|
140
140
|
classified_mac: MACClassification,
|
|
141
141
|
) -> None:
|
|
@@ -144,7 +144,7 @@ def inspect_local_individual_aai(
|
|
|
144
144
|
|
|
145
145
|
def inspect_local_group(
|
|
146
146
|
args: argparse.Namespace,
|
|
147
|
-
index:
|
|
147
|
+
index: IEEEIndexCatalog,
|
|
148
148
|
eval_flags: EvaluatedFlags,
|
|
149
149
|
classified_mac: MACClassification,
|
|
150
150
|
) -> None:
|
|
@@ -152,14 +152,17 @@ def inspect_local_group(
|
|
|
152
152
|
|
|
153
153
|
|
|
154
154
|
def inspect_zero_address(
|
|
155
|
-
args:argparse.Namespace,
|
|
155
|
+
args: argparse.Namespace,
|
|
156
|
+
index: IEEEIndexCatalog,
|
|
157
|
+
eval_flags: EvaluatedFlags,
|
|
158
|
+
classified_mac: MACClassification,
|
|
156
159
|
) -> None:
|
|
157
160
|
print("Zero")
|
|
158
161
|
|
|
159
162
|
|
|
160
163
|
def inspect_broadcast_address(
|
|
161
164
|
args: argparse.Namespace,
|
|
162
|
-
index:
|
|
165
|
+
index: IEEEIndexCatalog,
|
|
163
166
|
eval_flags: EvaluatedFlags,
|
|
164
167
|
classified_mac: MACClassification,
|
|
165
168
|
) -> None:
|
|
@@ -167,7 +170,7 @@ def inspect_broadcast_address(
|
|
|
167
170
|
|
|
168
171
|
|
|
169
172
|
def inspect_ieee_quadrants(
|
|
170
|
-
args: argparse.Namespace, index:
|
|
173
|
+
args: argparse.Namespace, index: IEEEIndexCatalog, eval_flags: EvaluatedFlags
|
|
171
174
|
) -> int:
|
|
172
175
|
classified_mac = classify_mac(args.value)
|
|
173
176
|
params: InspectionParams = {
|