Gentlemen,
I am using NetAddr::IP to break down a range of addresses given, the base address, the stop address, and the subnet mask, in bit format.
The problem that I am having is with getting the address that is 1 higher than the broadcast address for the previous subnet work. Below you will see code, with comments inline.
sub subnet_recurse {
my $netaddr_ref = shift;
my $endaddr_ref = shift;
my $new_addmask;
The parameters are references to NetAddr::IP objects
print "<hr><b>base: " . $$netaddr_ref->network() "</b><br>";
my $hostnum = 0;
foreach ($$netaddr_ref->hostenum()){
print "add$hostnum: " . $_ ."<br>";
$hostnum++;
}
print "<b>brdc:".$$netaddr_ref->broadcast()."</b><br><hr>";
Print out the stuff that is given to me from the objects.
my $net_broadcast =
NetAddr::IP->new($$netaddr_ref->broadcast()->addr());
Create new NetAddr::IP ojbect with the broadcast ip address
my $new_netaddr=NetAddr::IP->new($net_broadcast->addr())+1;
Use overloaded "+" as defined by the
specificationprint "<b>brd: " . $net_broadcast->addr() ."</b><br>";
#print "<b>new: " . $new_netaddr->addr() . "</b><br>";
#if( $new_netaddr->within($$endaddr_ref) ){
# subnet_recurse( \$new_netaddr, $endaddr_ref );
#} else { return; }
return;
}
The resulting output is as follows:
host: 192.168.1.0/29
mask: 255.255.255.248
base: 192.168.1.0/29
add0: 192.168.1.1/32
add1: 192.168.1.2/32
add2: 192.168.1.3/32
add3: 192.168.1.4/32
add4: 192.168.1.5/32
add5: 192.168.1.6/32
brdc: 192.168.1.7/29
192.168.1.7/32brd: 192.168.1.7
This has held me up all day, and is starting to become frustrating. Thanks for any help in advance.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.