M
M
Max2019-04-14 22:52:22
Nginx
Max, 2019-04-14 22:52:22

How to test blocking by IP set in Nginx / Apache?

Good afternoon!
The server is periodically loaded by various scraper bots. I check what kind of bots through awk parsing the logs and sorting them in descending order by the number of requests, then I add these IP / subnets to the blacklist.conf list, which is included in each domain config on the server. There are several servers, I do manual synchronization of the blacklist.
A couple of hundred such IP / subnets have already accumulated. And new IP addresses are constantly added, many of them duplicate each other, for example:
144.76.0.0/16
144.76.118.82
How to set up testing so that fresh IP addresses before entering into the server config first check whether it is already blocked or not? Is there a utility or online service where you can upload your Blacklist by masks and IP list and see which rule blocks it? Googled for an hour...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artem @Jump, 2019-04-15
Tag

How to set up testing so that fresh IP addresses before entering into the server config first check whether it is already blocked or not?
Banal list search.
Is there a utility or online service where you can upload your Blacklist by masks and IP list and see which rule blocks it?
What is it like?

P
Pavel Mezhuev, 2019-04-15
@mezhuev

Is there a utility or online service where you can upload your Blacklist by masks and IP list and see which rule blocks it?

As one of many options: https://metacpan.org/pod/NetAddr::IP
Example
#!/usr/bin/perl

use 5.010;
use strict;
use warnings;

use NetAddr::IP;

my @list = ('144.76.0.0/16', '144.76.118.82', '144.76.119.28', '144.76.67.0/24', '144.75.0.41');
my @result;
foreach my $ip (@list) {
    push(@result, NetAddr::IP->new($ip));
}
@result = NetAddr::IP::compact(@result);
foreach my $ip (@result) {
    say $ip->cidr;
}

Результат выполнения:
144.75.0.41/32
144.76.0.0/16

PS Dmitry Shitskov speaks the matter, fight the problem in the wrong place.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question