mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-03-30 23:03:03 -07:00
FE+BE: fake MAC standardization (FA:CE) #1344
Signed-off-by: jokob-sk <jokob.sk@gmail.com>
This commit is contained in:
@@ -144,7 +144,7 @@ function validateRegex(elem) {
|
||||
} else {
|
||||
iconSpan.html("<i class='fa fa-xmark'></i>");
|
||||
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() {
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -72,11 +72,25 @@ def generate_deterministic_guid(plugin, primary_id, secondary_id):
|
||||
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()
|
||||
|
||||
# Take the first 12 characters of the hash and format as a MAC address
|
||||
mac_hash = ':'.join(sha256_hash[i:i + 2] for i in range(0, 12, 2))
|
||||
# Take characters 4–11 (next 4 bytes) to form the rest of the MAC address
|
||||
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}"
|
||||
|
||||
Reference in New Issue
Block a user