Bash script that generates a random MAC address: Difference between revisions
Jump to navigation
Jump to search
(6 intermediate revisions by the same user not shown) | |||
Line 8: | Line 8: | ||
<syntaxhighlight lang='bash'> | <syntaxhighlight lang='bash'> | ||
hexdump -n3 -e'/3 "52:54:00" 3/1 ":%02X"' /dev/random; echo "" | hexdump -n3 -e'1/3 "52:54:00" 3/1 ":%02X"' /dev/random; echo "" | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Options | ==Options== | ||
-n<''number''> Interpret only ''number'' bytes of the input. | -n<''number''> Interpret only ''number'' bytes of the input. | ||
Line 17: | Line 17: | ||
-e'''format-string''' | -e'''format-string''' | ||
Format String | ==Format String== | ||
A format string contains any number of format units, separated by whitespaces. | A format string contains any number of format units, separated by whitespaces. | ||
A format unit contains up to three items: an iteration count, a byte count, and a format: | -e'''format-unit-1'' ''format-unit-2'' ...' ... | ||
A '''format unit''' contains up to three items: an iteration count, a byte count, and a format: | |||
* The iteration count is optional. It is a positive integer that defaults to 1. Each format is applied iteration count times. | * The iteration count is optional. It is a positive integer that defaults to 1. Each format is applied iteration count times. | ||
* The byte count is an optional positive integer that specifies the number of bytes to be interpreted by each iteration of the format. | * The byte count is an optional positive integer that specifies the number of bytes to be interpreted by each iteration of the format. | ||
The following configuration specifies an iteration count of 1 and a byte count of 2: | |||
... -e'1/2 "''format''"' | ... -e'1/2 "''format''"' | ||
The format | The '''format''' is required and must be surrounded by double quotes (" "). It is interpreted as a fprintf-style format string. | ||
The following displays two random bytes as four hexadecimal characters, followed by a new line: | |||
hexdump -n2 -e'1/2 "%X" 1/1 "\n"' /dev/random |
Latest revision as of 00:12, 20 March 2019
Internal
Overview
hexdump -n3 -e'1/3 "52:54:00" 3/1 ":%02X"' /dev/random; echo ""
Options
-n<number> Interpret only number bytes of the input.
-e'format-string'
Format String
A format string contains any number of format units, separated by whitespaces.
-e'format-unit-1 format-unit-2 ...' ...
A format unit contains up to three items: an iteration count, a byte count, and a format:
- The iteration count is optional. It is a positive integer that defaults to 1. Each format is applied iteration count times.
- The byte count is an optional positive integer that specifies the number of bytes to be interpreted by each iteration of the format.
The following configuration specifies an iteration count of 1 and a byte count of 2:
... -e'1/2 "format"'
The format is required and must be surrounded by double quotes (" "). It is interpreted as a fprintf-style format string.
The following displays two random bytes as four hexadecimal characters, followed by a new line:
hexdump -n2 -e'1/2 "%X" 1/1 "\n"' /dev/random