Last active
September 15, 2018 03:04
-
-
Save nanpuyue/7d4a31622d7523361fc51f608465d553 to your computer and use it in GitHub Desktop.
将前缀长度转换为子网掩码
This file contains 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
#!/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