.config
.emacs.d
.gkrellm2
.local
bin
Chatty
Checking-repo
Logc
Logs
Update
Update-kernel
Update-pkg
WinBox
backupSynology
backupSynologyMac
bgp-check
bin-cp
browser-x
chardetect
chatty-run
cidr2mask
cleaner
cleanertmp
cmus-control
cmus-shell
cpumhz
debugger
dmenumount
dmenuumount
dmenuunicode
docker-start
dwmstatusbar
eix-repos-sync
epylint
euscan
ext
f2py
f2py3
f2py3.6
f2py3.7
f2py3.8
flask
futurize
gentoo-test
geoip
get-meraki-network-list
getforecast
gfetch
gfg
git-delete-branch
git-init-folder
gswitch
haruhi-dl
iptables-restart
iptables-update
isort
jupyter-note
mailsync
mask2cidr
minecraft-launcher
mount-synology
mouse-set
night
notify-program
password-manager
pasteurize
pinger
pwiz.py
pylint
pyreverse
rasp
rcon
record
remove-kernel
runJava
saver-off
sb-battery
sb-clock
sb-cpu
sb-mail
sb-mem
sb-music
sb-network
sb-temp
sb-volume
sb-weather
screen-switcher
screenshot
screenshot-area
set-wallpaper
shut-sup-rest
sidebar-restore-macos
speedtest-cli
ssh-permissions
stream
suspend-at-time
symilar
tea
temp
term-wmi
tester-ebuild
tester-ubuntu
tmux-display-fix
trans
twitch
video-convert
volume
welcomer
welcomer-serwer
wheel
wsl-notify
wylaczoff
yatqa
youtube-dl
yt-mp3
yt-video
yt-video-cut
.parallel
Library
.alacritty.yml
.gitconfig
.gitconfig.local
.gitignore
.markdownlint.json
.signature
.skhdrc
.tmux.conf
.vimrc
.vimrc-def
.wall.jpg
.xinitrc
.yabairc
.zshrc
21 lines
798 B
Bash
Executable File
21 lines
798 B
Bash
Executable File
#!/bin/bash
|
|
mask2cidr() {
|
|
local mask=$1
|
|
|
|
# In RFC 4632 netmasks there's no "255." after a non-255 byte in the mask
|
|
local left_stripped_mask=${mask##*255.}
|
|
local len_mask=${#mask}
|
|
local len_left_stripped_mask=${#left_stripped_mask}
|
|
|
|
local conversion_table=0^^^128^192^224^240^248^252^254^
|
|
local number_of_bits_stripped=$(((len_mask - len_left_stripped_mask) * 2))
|
|
local signifacant_octet=${left_stripped_mask%%.*}
|
|
|
|
local right_stripped_conversion_table=${conversion_table%%$signifacant_octet*}
|
|
local len_right_stripped_conversion_table=${#right_stripped_conversion_table}
|
|
local number_of_bits_from_conversion_table=$((len_right_stripped_conversion_table / 4))
|
|
echo $((number_of_bits_stripped + number_of_bits_from_conversion_table))
|
|
}
|
|
|
|
mask2cidr "$@"
|