Skip to content

Instantly share code, notes, and snippets.

@tiveone
tiveone / netutils.sh
Created April 27, 2012 05:14
Convert netmask to cidr.
#!/bin/bash
function ::netmask2cidr()
{
case $1 in
0x*)
local hex=${1#0x*} quad=
while [ -n "${hex}" ]; do
local lastbut2=${hex#??*}
quad=${quad}${quad:+.}0x${hex%${lastbut2}*}