Skip to content

Instantly share code, notes, and snippets.

@cbp44
Last active October 6, 2023 09:51
Show Gist options
  • Save cbp44/4a3dcea41691c9747e0a6c7e5c1db27c to your computer and use it in GitHub Desktop.
Save cbp44/4a3dcea41691c9747e0a6c7e5c1db27c to your computer and use it in GitHub Desktop.
Random Windows hostname generator

Random Windows Hostname from Linux Shell

Shell function one-liner to produce a pseudorandom hostname in the style of Windows 7, Windows 8 and Windows 10 e.g. DESKTOP-V1XZZQ3

random_windows_hostname() {
    printf "DESKTOP-$(/usr/bin/tr -dc A-Z0-9 </dev/urandom | /usr/bin/head -c 7)"
}
echo "$(random_windows_hostname)"   # produces DESKTOP-V1XZZQ3

Further Reading and Sources

  1. Microsoft Windows hostname specs
#!/bin/sh
set -eu
# Generates a random DESKTOP-XXXXXXX hostname in line with Windows 7, Windows 10
# The returned hostname is not terminated by a newline so it can be used for variables.
#
# see: https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-vista/cc749460(v=ws.10)
#
# usage: random_windows_hostname
# out: DESKTOP-V1XZZQ3
random_windows_hostname() {
printf "DESKTOP-$(/usr/bin/tr -dc A-Z0-9 </dev/urandom | /usr/bin/head -c 7)"
}
# Example usage
random_windows_hostname
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment