在写一个脚本时需要实现掩码位和掩码之间的转换,想简单的通过shell 实现,在openwrt程序上刚好有此脚本,内容如下: 1#!/bin/bash 2# code from www.361way.com 3mask2cdr () 4{ 5 # Assumes there's no "255." after a non-255 byte in the mask 6 local x=${1##*255.} 7 set -- 0^^^128^192^224^240^248^252^254^ $(( (${#1} - ${#x})*2 )) ${x%%.*} 8 x=${1%%$3*} 9 echo $(( $2 + (${#x}/4) )) 10} 11cdr2mask () 12{ 13 # Number of args to shift, 255..255, first non-255 byte, zeroes 14 set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 %……
Continue reading