randmac.py: Generating LAA MAC Addresses
Sometimes, and in some select situations, I want to share a screenshot or some terminal output that contains MAC addresses. But for privacy reasons, I do not want to reveal the actual MAC addresses. Why? Because they’re unique identifiers (unless intentionally changed).
If the output only contained one or two physical addresses, I could manually mask them. But I wanted to explore another way to solve this problem. So, I wrote a Python module that pseudo randomizes MAC addresses for me.
So not to confuse myself, or others that may see the output, with what is the actual MAC vs randomized, I use the locally administered address (LAA) format. This means tje randomized MAC addresses from my module can be identified as such.
locally administered addresses
To differentiate MAC addresses, as stated above, the module creates Locally Administered Addresses (LAA).
The LAA is distinguished by setting the second least significant bit (LSB) of the addresses first octet. If the second LSB is set to 1, the address is administered locally.
For example, the first octet of d6:70:b6:a2:b8:8a
contains d6
(2 hex digits). The binary representation of the first octect is 11010110
. Where bits 7-4 = 1101
or hex digit d
, and then bits 3-0 = 0110
or hex digit 6
.
The second LSB is 1. It’s bit 1 in the table below (the value two from the far right).
b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |
---|---|---|---|---|---|---|---|
1 | 1 | 0 | 1 | 0 | 1 | 1 | 0 |
MSB | LSB |
So this represents a unicast LAA. Here’s how we know it’s unicast:
b0 values:
- 0: unicast
- 1: multicast
b1 values:
- 0: globally unique (OUI enforced)
- 1: locally administered
LAA identifiers
Here are other possible values that identify unicast LAA addresses:
- LSB
0010
=02:00:00:00:00:00
- LSB
0110
=06:00:00:00:00:00
- LSB
1010
=0a:00:00:00:00:00
- LSB
1110
=0e:00:00:00:00:00
Note: 0
in the MAC address examples above could be any hexadecimal digit.
formats
The module supports a few common MAC address formats and can output using any of these:
FF-FF-FF-FF-FF-FF
FF.FF.FF.FF.FF.FF
FFFF.FFFF.FFFF
One caveat is the way I implemented formatting. It requires you to tell the module what format you want. It needs to know what format for output. For example providing something like 00-00-00-00-00-00
to the module would return something like 00-00-00-c7-11-fc
.
This is clunky, and could be improved. Let me know how you think it could be better.
installation
I put the module on PyPi so that it can be installed using pip:
pip install randmac
example usage
>>> from randmac import RandMac
>>> RandMac("00-00-00-00-00-00")
'00-00-00-c7-11-fc'
>>> RandMac("00:00:00:00:00:00", True)
'ba:ac:5f:09:fc:bb'
>>> RandMac("0000.0000.0000", True)
'fe84.857f.900f'
or
$ python3 randmac.py 00:00:00:00:00:00
00:00:00:fc:e1:5b
$ python3 randmac.py 00:00:00:00:00:00 -f
2a:81:b0:e7:1d:08
links
you can find it at these locations on the Internet:
feedback
I’d love to hear any constructive feedback or suggestions on how to improve this project.