toadi has asked for the wisdom of the Perl Monks concerning the following question:
(This is just demo code to illustrate my point)
I just want to generate a list of IP's. I know the start ip and the network mask and want to generate the whole list of IP's from that range. I tried this approach, but there , must be a cleaner way to do this...%maskcount = ( "/25" => "128", "/26" => "64", "/27" => "32", "/28" => "16"); # loop POPs while($line=<STDIN>) { chomp($line); next unless ($line=~/^\d/); ($ipbase,$mask)=split(/;/,$line); @ip=split(/\./,$ipbase); $areacode =~ s/^0//; print "$areacode: $ipbase/$mask\n"; # do not load first (=network) and second (=gateway) ip addressess $startip=2; # do not load last (=broadcast) ip address $endip=$maskcount{$mask}-1; print $endip; for ($cnt=$startip;$cnt<$endip;$cnt++) { $ipend[0]=$ip[0]; $ipend[1]=$ip[1]; $ipend[2]=$ip[2]; $ipend[3]=$ip[3]+$cnt; if ($ipend[3]>255) { $ipend[2]=$ip[2]+1; $ipend[3]=$ip[3]-255; } $ipend = join(".",@ipend); print "$ipend\n"; } }
--
My opinions may have changed,
but not the fact that I am right
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IP troubles
by jwest (Friar) on Dec 18, 2001 at 02:07 UTC | |
by toadi (Chaplain) on Dec 18, 2001 at 14:41 UTC | |
by jwest (Friar) on Dec 18, 2001 at 19:27 UTC | |
|
Re: IP troubles
by atcroft (Abbot) on Dec 18, 2001 at 11:38 UTC |