Last active
June 17, 2024 12:32
-
-
Save kwilczynski/5d37e1cced7e76c7c9ccfdf875ba6c5b to your computer and use it in GitHub Desktop.
CIDR to netmask in bash.
This file contains hidden or 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
# Return netmask for a given network and CIDR. | |
cidr_to_netmask() { | |
value=$(( 0xffffffff ^ ((1 << (32 - $1)) - 1) )) | |
echo "$(( (value >> 24) & 0xff )).$(( (value >> 16) & 0xff )).$(( (value >> 8) & 0xff )).$(( value & 0xff ))" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ckuhtz, I am glad you found it useful!