Does someone have example in Perl of how I can calculate the broadcast IP from an IP address and netmask?
views:
76answers:
2
+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
2010-09-21 19:34:35
Ether this is very simple example , sorry about my question
shulus
2010-09-21 19:42:05
+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
2010-09-21 19:35:41
NetAddr::IP has been my goto for anything IP related for a while now; it handles everything.
Oesor
2010-09-21 20:28:50