summaryrefslogtreecommitdiffstats
path: root/make_ip_del_recovered.pl
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-09 13:11:53 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-09 13:11:53 +0000
commit655cb1b8222b0a587bbdd5c1357d55682332c665 (patch)
tree65a83d3c36e6d4c4d57cec63f63d2019b2dfc93b /make_ip_del_recovered.pl
parentInitial commit. (diff)
downloadwhois-655cb1b8222b0a587bbdd5c1357d55682332c665.tar.xz
whois-655cb1b8222b0a587bbdd5c1357d55682332c665.zip
Adding upstream version 5.5.21.upstream/5.5.21
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'make_ip_del_recovered.pl')
-rwxr-xr-xmake_ip_del_recovered.pl69
1 files changed, 69 insertions, 0 deletions
diff --git a/make_ip_del_recovered.pl b/make_ip_del_recovered.pl
new file mode 100755
index 0000000..8cc3a3d
--- /dev/null
+++ b/make_ip_del_recovered.pl
@@ -0,0 +1,69 @@
+#!/usr/bin/perl
+# https://www.iana.org/assignments/ipv4-recovered-address-space/ipv4-recovered-address-space-2.csv
+
+use warnings;
+use strict;
+use autodie;
+
+use Text::CSV;
+use Net::Patricia;
+use Net::CIDR;
+use Net::IP;
+
+my $csv = Text::CSV->new;
+my $pt = parse_ip_del('ip_del_list');
+
+open(my $in, '<', 'ipv4-recovered-address-space-2.csv');
+open(my $out, '>', 'ip_del_recovered.h');
+
+while (my $row = $csv->getline($in)) {
+ next if $row->[0] eq 'Start address';
+ next if $row->[5] ne 'ALLOCATED';
+ my ($first_ip, $last_ip, undef, undef, $server) = @$row;
+
+ my @networks =
+ grep {
+ my $server_recovered = $pt->match_string($_->ip);
+ $server_recovered and $server_recovered ne $server;
+ }
+ map { Net::IP->new($_) }
+ Net::CIDR::range2cidr($first_ip . '-' . $last_ip);
+ next if not @networks;
+
+ print $out "/* $first_ip - $last_ip */\n";
+ print $out sprintf(qq|{ %sUL, %sUL, "%s" },\n|,
+ $_->intip,
+ ((~(0xffffffff >> $_->prefixlen)) & 0xffffffff),
+ $server
+ ) foreach @networks;
+}
+
+close($in);
+close($out);
+exit;
+
+sub parse_ip_del {
+ my ($file) = @_;
+
+ my $pt = new Net::Patricia;
+
+ open(my $in, '<', $file);
+ while (<$in>) {
+ # this code is copied from make_ip_del.pl
+ chomp;
+ s/#.*$//;
+ s/^\s+//; s/\s+$//;
+ next if /^$/;
+
+ die "format error: $_" if not /^([\d\.]+)\/(\d+)\s+([\w\.]+)$/;
+ my $network = "$1/$2";
+ my $server = $3;
+
+ $server = "whois.$server.net" if $server !~ /\./;
+
+ $pt->add_string($network, $server) or die;
+ }
+
+ return $pt;
+}
+