A simple Python project for working with MAC addresses, providing utilities to retrieve the current device's MAC address and perform device authentication based on MAC addresses.
- Get MAC Address: Retrieve the MAC address of the current device
- Device Authentication: Authenticate devices based on a whitelist of MAC addresses
- Python 3.x
- Standard library only (uses the built-in
uuid
module)
from main import get_mac_address
# Get the current device's MAC address
mac = get_mac_address()
print(f"MAC Address: {mac}")
Or run the script directly:
python main.py
The ex.py
file demonstrates how to implement a simple device authentication system using MAC addresses:
from ex import authenticate_device
# Check if the current device is authorized
if authenticate_device():
# Proceed with application logic
pass
else:
# Handle unauthorized access
pass
Or run the script directly:
python ex.py
The get_mac_address()
function uses Python's uuid.getnode()
to get the MAC address as an integer, then converts it to the standard colon-separated hexadecimal format.
The authenticate_device()
function:
- Defines a list of allowed MAC addresses
- Retrieves the current device's MAC address
- Checks if the current MAC address is in the allowed list
- Returns True for authorized devices, False otherwise
To customize the list of allowed MAC addresses, modify the allowed_macs
list in ex.py
:
allowed_macs = ["a4:83:e7:xx:xx:xx", "b8:27:eb:xx:xx:xx"]
Replace with your actual MAC addresses (without the "xx:xx:xx" placeholders).
MAC address authentication should not be used as the sole security measure as MAC addresses can be spoofed. Consider using this as part of a broader security strategy.