tags:

views:

76

answers:

2

Does someone have example in Perl of how I can calculate the broadcast IP from an IP address and netmask?

+5  A: 

This can be done with the CPAN modules Net::IP and Net::Netmask:

my $ip = Net::IP->new('192.168.1.1');
my $block = Net::Netmask->new('192.168.1.1');

print "netmask: ", $ip->mask(), "\n";
print "broadcast: ", $block->broadcast(), "\n";
Ether
Ether this is very simple example , sorry about my question
shulus
+5  A: 

Why not use modules from CPAN. For example NetAddr::IP:

 my $ip = NetAddr::IP->new('124.2.4.6', '255.255.255.0');
 print $ip->broadcast();
Ivan Nevostruev
NetAddr::IP has been my goto for anything IP related for a while now; it handles everything.
Oesor