bcromwell has asked for the wisdom of the Perl Monks concerning the following question:

Basicly I am trying to use a perl script to convert Wildcard mask (Aka Reverse Mask or Cisco Mask) to standard mask (or even cidr). Is there anything out there what already does this? I already tried using NetAddr::IP but it will only go from Ipv4 with cidr to wildcard and not the other way around.

Replies are listed 'Best First'.
Re: Wildcard Mask to subnet mask
by AltBlue (Chaplain) on Jul 23, 2008 at 20:19 UTC
    $ perl -MNet::Netmask -le 'print Net::Netmask->new("10.11.0.0#0.0.0.25 +5")' 10.11.0.0/24
      Thank you guys, You are Great!!!
Re: Wildcard Mask to subnet mask
by ikegami (Patriarch) on Jul 23, 2008 at 20:24 UTC
    Looks like a wildcard mask is just the bitwise negation of a regular mask.
    my $mask_wild_dotted = '0.0.0.31'; my $mask_wild_packed = pack 'C4', split /\./, $mask_wild_dotted; my $mask_norm_packed = ~$mask_wild_packed; my $mask_norm_dotted = join '.', unpack 'C4', $mask_norm_packed; print("$mask_norm_dotted\n"); # 255.255.255.224