Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Wildcard Mask to subnet mask

by bcromwell (Initiate)
on Jul 23, 2008 at 19:48 UTC ( [id://699677]=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://699677]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (1)
As of 2024-07-23 02:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.