Skip to content

Instantly share code, notes, and snippets.

@nanpuyue
Last active September 15, 2018 03:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nanpuyue/7d4a31622d7523361fc51f608465d553 to your computer and use it in GitHub Desktop.
将前缀长度转换为子网掩码
#!/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