Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SmugZombie/3572f10325b2ea821cc4343186d5790e to your computer and use it in GitHub Desktop.
Save SmugZombie/3572f10325b2ea821cc4343186d5790e to your computer and use it in GitHub Desktop.
String to MAC address
const crypto = require('crypto');
function stringToMacAddress(input) {
// Create an MD5 hash of the input string
const hash = crypto.createHash('md5').update(input).digest('hex');
// Convert the hash to MAC address format
const macAddress = hash.match(/.{1,2}/g).slice(0, 6).join(':');
return macAddress;
}
// Test the function
console.log(stringToMacAddress('hello world')); // Example output: '5e:b6:3b:76:24:f4'
console.log(stringToMacAddress('hello worLd')); // Example output: '4f:a5:6c:87:35:e5'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment