FE+BE: fake MAC standardization (FA:CE) #1344

Signed-off-by: jokob-sk <jokob.sk@gmail.com>
This commit is contained in:
jokob-sk
2025-12-30 09:56:23 +11:00
parent 30294ef9bc
commit eb125a84fe
2 changed files with 22 additions and 8 deletions

View File

@@ -144,7 +144,7 @@ function validateRegex(elem) {
} else { } else {
iconSpan.html("<i class='fa fa-xmark'></i>"); iconSpan.html("<i class='fa fa-xmark'></i>");
showModalOk('WARNING', getString("Gen_Invalid_Value")); showModalOk('WARNING', getString("Gen_Invalid_Value"));
inputElem.attr("data-is-valid", "0"); inputElem.attr("data-is-valid", "0");
} }
} }
@@ -450,10 +450,10 @@ function addOptionFromModalInput() {
// -------------------------------------------------------- // --------------------------------------------------------
// Generate a random MAC address starting 00:1A // Generate a random MAC address starting FA:CE
function generate_NEWDEV_devMac() { function generate_NEWDEV_devMac() {
const randomHexPair = () => Math.floor(Math.random() * 256).toString(16).padStart(2, '0').toUpperCase(); const randomHexPair = () => Math.floor(Math.random() * 256).toString(16).padStart(2, '0').toUpperCase();
$('#NEWDEV_devMac').val(`00:1A:${randomHexPair()}:${randomHexPair()}:${randomHexPair()}:${randomHexPair()}`.toLowerCase()); $('#NEWDEV_devMac').val(`FA:CE:${randomHexPair()}:${randomHexPair()}:${randomHexPair()}:${randomHexPair()}`.toLowerCase());
} }

View File

@@ -72,11 +72,25 @@ def generate_deterministic_guid(plugin, primary_id, secondary_id):
return str(uuid.UUID(hashlib.md5(data).hexdigest())) return str(uuid.UUID(hashlib.md5(data).hexdigest()))
def string_to_mac_hash(input_string): # -------------------------------------------------------------------------------
# Calculate a hash using SHA-256 def string_to_fake_mac(input_string):
"""
Generate a deterministic fake MAC address from an input string.
The MAC address is hex-valid and begins with a FA:CE prefix
to clearly indicate it is synthetic.
Args:
input_string (str): The input string to hash into a MAC address.
Returns:
str: A MAC address string in the format 'fa:ce:xx:xx:xx:xx'.
"""
# Calculate a SHA-256 hash of the input string
sha256_hash = hashlib.sha256(input_string.encode()).hexdigest() sha256_hash = hashlib.sha256(input_string.encode()).hexdigest()
# Take the first 12 characters of the hash and format as a MAC address # Take characters 411 (next 4 bytes) to form the rest of the MAC address
mac_hash = ':'.join(sha256_hash[i:i + 2] for i in range(0, 12, 2)) rest = ':'.join(sha256_hash[i:i + 2] for i in range(4, 12, 2))
return mac_hash # Prepend the FA:CE prefix to clearly mark this as a fake MAC
return f"fa:ce:{rest}"