Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
cidr2mask() {
local i mask=""
local full_octets=$(($1/8))
local partial_octet=$(($1%8))
for ((i=0;i<4;i+=1)); do
if [ $i -lt $full_octets ]; then
mask+=255
elif [ $i -eq $full_octets ]; then
mask+=$((256 - 2**(8-$partial_octet)))
else
mask+=0
fi
test $i -lt 3 && mask+=.
done
echo $mask
}
@linuxenko
Copy link
Author

linuxenko commented Jul 5, 2017

cat ss | awk -F "/" '{"cidr2mask " $2 | getline d; print "route " $1 " " d}'
cat ss | sed -E "s/// /" | sed -E "s/\s$//" | awk '{system("echo -n "route " $1 " ";cidr2mask " $2)}' > aa

Loading

@linuxenko
Copy link
Author

linuxenko commented Jul 5, 2017

route 5.45.192.0 255.255.192.0
route 5.45.196.0 255.255.255.0
route 5.45.205.0 255.255.255.0
route 5.45.213.0 255.255.255.0
route 5.45.217.0 255.255.255.0
route 5.45.229.0 255.255.255.0
route 5.45.232.0 255.255.255.0
route 5.45.240.0 255.255.255.0
route 5.255.192.0 255.255.255.0
route 5.255.195.0 255.255.255.0
route 5.255.196.0 255.255.255.0
route 5.255.200.0 255.255.255.0
route 5.255.255.0 255.255.255.0
route 37.9.64.0 255.255.255.0
route 37.9.112.0 255.255.255.0
route 37.140.128.0 255.255.255.0
route 77.88.0.0 255.255.255.0
route 77.88.8.0 255.255.255.0
route 77.88.21.0 255.255.255.0
route 77.88.35.0 255.255.255.0
route 77.88.44.0 255.255.255.0
route 77.88.54.0 255.255.255.0
route 77.88.55.0 255.255.255.0
route 84.201.128.0 255.255.255.0
route 87.250.224.0 255.255.224.0
route 87.250.247.0 255.255.224.0
route 87.250.250.0 255.255.224.0
route 87.250.251.0 255.255.224.0
route 87.250.254.0 255.255.224.0
route 87.250.255.0 255.255.224.0
route 93.158.128.0 255.255.224.0
route 93.158.134.0 255.255.224.0
route 95.108.128.0 255.255.128.0
route 100.43.64.0 255.255.128.0
route 100.43.87.0 255.255.128.0
route 130.193.32.0 255.255.128.0
route 141.8.128.0 255.255.128.0
route 141.8.149.0 255.255.128.0
route 178.154.128.0 255.255.128.0
route 178.154.131.0 255.255.128.0
route 178.154.170.0 255.255.128.0
route 199.21.96.0 255.255.252.0
route 199.36.240.0 255.255.252.0
route 213.180.192.0 255.255.252.0
route 213.180.193.0 255.255.252.0
route 213.180.199.0 255.255.252.0
route 213.180.202.0 255.255.252.0
route 213.180.204.0 255.255.252.0

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment