Skip to content

Commit b3ed603

Browse files
committed
Script bugfix.
1 parent da3e927 commit b3ed603

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

.gitignore

Whitespace-only changes.

antizapret.pl

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,38 @@
33
use strict;
44
use warnings FATAL => 'all';
55

6-
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`;
6+
#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`;
7+
my @ips = `fetch -o - http://api.antizapret.info/group.php | sort | uniq`;
78

89
my $buf = '';
910
my $cnt = 0;
1011
my $mask = '';
1112

1213
foreach $ip (@ips) {
13-
if ($mask == '') {
14-
($mask) = ($ip =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)/);
15-
$buf = $ip;
16-
$cnt = 1;
17-
} elsif (starts_with($ip, $mask)) {
18-
$buf .= $ip;
19-
$cnt++;
20-
} elsif ($cnt >= 10) {
21-
print $mask."0/24\n";
22-
$buf = $mask = '';
23-
$cnt = 0;
24-
} else {
25-
print $buf;
26-
$buf = $mask = '';
27-
$cnt = 0;
28-
}
14+
if ($mask == '') {
15+
($mask) = ($ip =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)/);
16+
$buf = $ip;
17+
$cnt = 1;
18+
}
19+
elsif (starts_with($ip, $mask)) {
20+
$buf .= $ip;
21+
$cnt++;
22+
}
23+
else {
24+
if ($cnt >= 10) {
25+
print $mask . "0/24\n";
26+
}
27+
else {
28+
print $buf;
29+
}
30+
($mask) = ($ip =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)/);
31+
$buf = $ip;
32+
$cnt = 1;
33+
}
2934
}
3035

3136

3237

33-
sub starts_with
34-
{
38+
sub starts_with {
3539
return substr($_[0], 0, length($_[1])) eq $_[1];
3640
}

0 commit comments

Comments
 (0)