Skip to content

A Python utility for retrieving MAC addresses and implementing device authentication based on MAC address whitelisting

Notifications You must be signed in to change notification settings

timeless-residents/handson-mac-address

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

MAC Address Utilities

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.

Features

  • Get MAC Address: Retrieve the MAC address of the current device
  • Device Authentication: Authenticate devices based on a whitelist of MAC addresses

Requirements

  • Python 3.x
  • Standard library only (uses the built-in uuid module)

Usage

Getting the MAC Address

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

Device Authentication

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

How It Works

MAC Address Retrieval (main.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.

Device Authentication (ex.py)

The authenticate_device() function:

  1. Defines a list of allowed MAC addresses
  2. Retrieves the current device's MAC address
  3. Checks if the current MAC address is in the allowed list
  4. Returns True for authorized devices, False otherwise

Customization

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).

Security Note

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.

About

A Python utility for retrieving MAC addresses and implementing device authentication based on MAC address whitelisting

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages