Thread Subnet Calculator (10 answers)
Opened by Gast at 2007-10-12 10:48

renee
 2007-10-12 11:16
#100734 #100734
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/perl

use strict;
use warnings;

my $start = '10.10.10.0';
my $stop  = '10.10.20.0';
my $snm   = '255.255.0.0';
my $cidr  = '255.255.255.252';
my $end   = '0.0.0.3';
my $group = 4;

my $group_counter = 0;

    my @first_ip  = split /\./, $start;
    my @second_ip = split /\./, $stop;
    
    while(1){
        last if join( ".", @first_ip ) eq $stop;
        $group_counter++;

        print sprintf "%s %s %s %s\n", join(".", @first_ip),$snm,$cidr,$end;
        $first_ip[-1]++;

        for( reverse 1..3 ){
          if( $first_ip[$_] == 256 ){
              $first_ip[$_-1] += 1;
              $first_ip[$_]    = 0;
          }
        }
        if( $group_counter == 4 ){
            print "-" x 40, "\n";
            $group_counter = 0 ;
        }
    }
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread Subnet Calculator