Added function into a files not in zshrc

This commit is contained in:
2024-01-28 20:47:53 +01:00
parent b8aef151f2
commit 78ee3595ec
3 changed files with 41 additions and 37 deletions

21
.local/bin/cidr2mask Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
cidr2mask() {
local i mask=""
local full_octets=$(($1 / 8))
local partial_octet=$(($1 % 8))
for ((i = 0; i < 4; i += 1)); do
if [ $i -lt $full_octets ]; then
mask+=255
elif [ $i -eq $full_octets ]; then
mask+=$((256 - 2 ** (8 - partial_octet)))
else
mask+=0
fi
test $i -lt 3 && mask+=.
done
echo $mask
}
cidr2mask "$@"