Skip to content

Commit

Permalink
Script bugfix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed Feb 28, 2019
1 parent da3e927 commit b3ed603
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
Empty file added .gitignore
Empty file.
42 changes: 23 additions & 19 deletions antizapret.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,38 @@
use strict;
use warnings FATAL => 'all';

my @ips = `fetch -o - https://raw.githubusercontent.com/zapret-info/z-i/master/dump.csv | sed 1d | cut -d ';' -f 1 | tr "\\|" "\\n" | sed 's/^[ \\t]*//;s/[ \\t]*\$//' | sort | uniq`;
#my @ips = `fetch -o - https://raw.githubusercontent.com/zapret-info/z-i/master/dump.csv | sed 1d | cut -d ';' -f 1 | tr "\\|" "\\n" | sed 's/^[ \\t]*//;s/[ \\t]*\$//' | sort | uniq`;
my @ips = `fetch -o - http://api.antizapret.info/group.php | sort | uniq`;

my $buf = '';
my $cnt = 0;
my $mask = '';

foreach $ip (@ips) {
if ($mask == '') {
($mask) = ($ip =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)/);
$buf = $ip;
$cnt = 1;
} elsif (starts_with($ip, $mask)) {
$buf .= $ip;
$cnt++;
} elsif ($cnt >= 10) {
print $mask."0/24\n";
$buf = $mask = '';
$cnt = 0;
} else {
print $buf;
$buf = $mask = '';
$cnt = 0;
}
if ($mask == '') {
($mask) = ($ip =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)/);
$buf = $ip;
$cnt = 1;
}
elsif (starts_with($ip, $mask)) {
$buf .= $ip;
$cnt++;
}
else {
if ($cnt >= 10) {
print $mask . "0/24\n";
}
else {
print $buf;
}
($mask) = ($ip =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)/);
$buf = $ip;
$cnt = 1;
}
}



sub starts_with
{
sub starts_with {
return substr($_[0], 0, length($_[1])) eq $_[1];
}

0 comments on commit b3ed603

Please sign in to comment.