http://www.perlmonks.org?node_id=1035642


in reply to Net IP

I need to write a subnet mask calculator with perl. The extension Net::IP is really powerful.

Well, you could use that module. First thing to do is read its documentation, and off you go. Come back with some code to discuss.

Alternatively I just happen to have a calculator in my toolbox for calculating network, netmask and broadcast out of an IPv4 address in CIDR notation which could be worth being studied by you:

#!/usr/bin/perl # file cidr $m=pack B32,pop=~'/'x$'; printf"$` network %vd broadcast %vd netmask %vd\n",($z=eval$`)&$m,$z|~ +$m,$m; __END__ Example: cidr 209.197.123.153/27 209.197.123.153 network 209.197.123.128 broadcast 209.197.123.159 netm +ask 255.255.255.224
Consult the perl documentation for its various operators, perl special variables and internal functions.