Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- strict;
- use warnings;
- sub bloquear_conexoes {
- my (\$max_conexoes, \$intervalo_tempo) = @_;
- my %conexoes_por_ip;
- my %ips_bloqueados;
- my \$contador = 0;
- while (1) {
- my \$ip_cliente = obter_ip_cliente();
- if (defined \$ip_cliente) {
- \$conexoes_por_ip{\$ip_cliente}++;
- \$contador++;
- if (\$conexoes_por_ip{\$ip_cliente} > \$max_conexoes) {
- bloquear_ip(\$ip_cliente);
- \$ips_bloqueados{\$ip_cliente} = 1;
- delete \$conexoes_por_ip{\$ip_cliente};
- }
- }
- sleep \$intervalo_tempo;
- \$contador = 0;
- %ips_bloqueados = ();
- }
- }
- sub bloquear_ip {
- my \$endereco_ip = shift;
- system("iptables -A INPUT -s \$endereco_ip -j DROP");
- print "O IP \$endereco_ip foi bloqueado com sucesso!";
- }
- my \$ip_bloqueado = '192.168.0.123';
- bloquear_ip(\$ip_bloqueado);
- bloquear_conexoes(10, 60);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement