"Fossies" - the Fresh Open Source Software Archive

Member "whois/make_ip_del_recovered.pl" (27 Jul 2017, 775 Bytes) of package /linux/privat/whois_5.5.9.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "make_ip_del_recovered.pl" see the Fossies "Dox" file reference documentation.

    1 #!/usr/bin/perl
    2 # https://www.iana.org/assignments/ipv4-recovered-address-space/ipv4-recovered-address-space-2.csv
    3 
    4 use warnings;
    5 use strict;
    6 use autodie;
    7 
    8 use Text::CSV;
    9 use Net::CIDR;
   10 use Net::IP;
   11 
   12 my $csv = Text::CSV->new;
   13 
   14 open(my $in, '<', 'ipv4-recovered-address-space-2.csv');
   15 open(my $out, '>', 'ip_del_recovered.h');
   16 
   17 while (my $row = $csv->getline($in)) {
   18     next if $row->[0] eq 'Start address';
   19     next if $row->[5] ne 'ALLOCATED';
   20 
   21     print $out '/* ' . $row->[0] . ' - ' . $row->[1] . " */\n";
   22     my @networks =
   23         map { Net::IP->new($_) }
   24         Net::CIDR::range2cidr($row->[0] . '-' . $row->[1]);
   25     print $out sprintf(qq|{ %sUL, %sUL, "%s" },\n|,
   26         $_->intip,
   27         ((~(0xffffffff >> $_->prefixlen)) & 0xffffffff),
   28         $row->[4]
   29     ) foreach @networks;
   30 }
   31 
   32 close($in);
   33 close($out);
   34