How can i generate a valid random mac adress with bash.
The first half of the adress should always stay same like this
00-60-2F-xx-xx-xx
just the x value should be generated random?
|
How can i generate a valid random mac adress with bash. The first half of the adress should always stay same like this
just the x value should be generated random? |
||||
|
|||||
|
|
Here is a fish. This shell script will generate the random string you seek:
I did just have something here that showed how to run it from the command line, but after looking at Dennis Williamson convoluted (but upvoted) solution I see that the answer that people expect is the one where they don't have to do any work themselves. |
|||||||
|
The keys to the way this works:
|
|||||||||||
|
|
In the past I've done this using:
but that will only make them in the range 0-9. For my purposes, that was good enough. Probably a better solution would be to use printf:
Here's how that works:
|
|||||||||||||
|
|
The shortest way I could come up with was using hexdump directly
Tested on GNU/Linux |
|||
|
Another one line solution
Same thing in upper case
Generate it for a Bash environment variable
Details:
|
||||
|
|
|
|||
|
|
|
Using standard tools, either
or
might be the shortest of all. |
|||
|
|
|
|||||
|
echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"'– artistoex Jan 20 '12 at 13:56