Created
August 21, 2021 05:10
-
-
Save rohan-molloy/c5608cd18a2d5112b16fbee29e2fd7c3 to your computer and use it in GitHub Desktop.
generate a random ipv6 address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generate a Random Mac | |
function randomMac() { | |
return "XX:XX:XX:XX:XX:XX".replace(/X/g, function() { | |
return "0123456789ABCDEF".charAt(Math.floor(Math.random() * 16)) | |
} | |
) | |
}; | |
// Generate IPv6 EUI64 | |
function ip6eui(prefix,mac) { | |
return "".concat (prefix, | |
":", | |
mac.split(":")[0] ^ 2, mac.split(":")[1], | |
":", | |
mac.split(":")[2], "ff", | |
":", | |
"fe", mac.split(":")[3], | |
":", | |
mac.split(":")[4], mac.split(":")[5] | |
); | |
}; | |
prefix='2001:db8:' | |
console.log(ip6eui(prefix,randomMac() )); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment