Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
将前缀长度转换为子网掩码
#!/bin/bash
# date: 2018-03-03
# license: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt
# author: nanpuyue <nanpuyue@gmail.com> https://blog.nanpuyue.com
num=$(( 4294967296 - 2**(32-$1) ))
for i in {3..0};do
echo -n $(( $num / 256**$i ))
num=$(( $num % 256**$i ))
[[ $i = 0 ]] && echo || echo -n .
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment