Improve gen_netmask

Add arguments to allow specify the CIDR range that the netmask should be
generated.