eui48_bit_distance package¶
Calculate distance in bits between EUI-48 (a.k.a. 48-bit MAC) strings.
- eui48_bit_distance.check_eui48(a: str, /) bool¶
Check if the input is an EUI-48 identifier.
Supported formats:
12:34:56:78:90:ab,12-34-56-78-90-aband1234.5678.90ab. Letters can be in upper or lower case.- Returns:
Trueif a is an EUI-48 identifier, otherwiseFalse.
- eui48_bit_distance.bytes_to_eui48(b: bytes, /, *, sep: str = ':', group: int = 2) str¶
Convert bytes into an EUI-48 identifier.
Supported formats:
12:34:56:78:90:ab,12-34-56-78-90-aband1234.5678.90ab. Set sep to either ‘:’ (the default value), ‘-’ or ‘.’. Set group to either 2 (the default value) or 4.Using sep and group arguments carelessly can result in output being in an unsupported format. Currently there are no guardrails against that.
- Returns:
b converted from
bytesinto EUI-48 identifier.
- eui48_bit_distance.int_to_eui48(i: int, /, *, sep: str = ':', group: int = 2) str¶
Convert an integer into an EUI-48 identifier.
Supported formats:
12:34:56:78:90:ab,12-34-56-78-90-aband1234.5678.90ab. Set sep to either ‘:’ (the default value), ‘-’ or ‘.’. Set group to either 2 (the default value) or 4.Using sep and group arguments carelessly can result in output being in an unsupported format. Currently there are no guardrails against that.
- Raises:
ValueError – If i cannot be represented by EUI-48.
- Returns:
i converted from
intinto EUI-48 identifier.
- eui48_bit_distance.eui48_to_bytes(a: str, /) bytes¶
Convert an EUI-48 identifier into bytes.
Supported formats:
12:34:56:78:90:ab,12-34-56-78-90-aband1234.5678.90ab. Letters can be in upper or lower case.check_eui48()can be used to check if the input is a valid EUI-48 identifier.- Raises:
ValueError – If a cannot be parsed as EUI-48 identifier.
- Returns:
a converted from EUI-48 identifier into
bytes.
- eui48_bit_distance.eui48_to_int(a: str, /) int¶
Convert an EUI-48 identifier into an integer.
Supported formats:
12:34:56:78:90:ab,12-34-56-78-90-aband1234.5678.90ab. Letters can be in upper or lower case.check_eui48()can be used to check if the input is a valid EUI-48 identifier.- Raises:
ValueError – If a cannot be parsed as EUI-48 identifier.
- Returns:
a converted from EUI-48 identifier into
int.
- eui48_bit_distance.eui48_bit_distance(a: str, b: str, /) int¶
Calculate bit distance between two EUI-48 identifiers.
- Returns:
The amount of bits that are different between a and b.
- eui48_bit_distance.eui48_find_similar(a: str, iterable: Iterable[str], /, *, cutoff: int = 8) list[tuple[int, str]]¶
Return EUI-48 identifiers and their distances from the reference EUI-48 identifier.
This function measures and orders output by the distances between a and every string in iterable. To reduce the number of elements in the output, it also drops inputs that have distance greater than cutoff.
- Returns:
A list of 2-tuples
(distance, EUI-48 identifier).