Skip to content

Lyssers/cidr2mask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

CIDR Range to Dotquad Subnet Mask Converter

Converts a CIDR range into a subnet mask e.g. from 24 to 255.255.255.0

Useful for some tools that may only accept one or another

Usage:

  1. Compile with GCC like:

gcc cidr2mask.c -o cidr2mask.o

  1. Run like:

./cidr2mask.o <cidr> e.g. ./cidr2mask.o 24

  1. Output:
Binary Subnet Mask: 11111111111111111111111100000000
Decimal Subnet Mask: 4294967040
Subnet Mask in Dotquad: 255.255.255.0

(Optional) sudo cp ./cidr2mask.o /usr/bin/cidr2mask to run it using just cidr2mask

The output is very verbose by default, which works for my needs, if you'd like a less verbose mode open an issue and I can do it!

Or alternatively use awk, xargs and tail, e.g.:

 ./cidr2mask.o 24 | tail -1 |  awk -F ': ' '{print $2}') >> somefile

or e.g. use it with subnetter

 echo $(ifconfig wlan0 | grep 'inet' | head -1 | awk -F ' ' '{print $2}')  $(cidr2mask 24 | tail -1 |  awk -F ': ' '{print $2}') | xargs subnetter 

About

Converts a CIDR range into a subnet mask.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages