Advertisement
dev017

block ip v2 (pl)

Jul 29th, 2023
112
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.96 KB | None | 1 0
  1. strict;
  2. use warnings;
  3.  
  4. sub bloquear_conexoes {
  5.     my (\$max_conexoes, \$intervalo_tempo) = @_;
  6.  
  7.     my %conexoes_por_ip;
  8.     my %ips_bloqueados;
  9.     my \$contador = 0;
  10.  
  11.     while (1) {
  12.         my \$ip_cliente = obter_ip_cliente();
  13.  
  14.         if (defined \$ip_cliente) {
  15.             \$conexoes_por_ip{\$ip_cliente}++;
  16.             \$contador++;
  17.  
  18.             if (\$conexoes_por_ip{\$ip_cliente} > \$max_conexoes) {
  19.                 bloquear_ip(\$ip_cliente);
  20.                 \$ips_bloqueados{\$ip_cliente} = 1;
  21.                 delete \$conexoes_por_ip{\$ip_cliente};
  22.             }
  23.         }
  24.  
  25.         sleep \$intervalo_tempo;
  26.  
  27.         \$contador = 0;
  28.         %ips_bloqueados = ();
  29.     }
  30. }
  31.  
  32. sub bloquear_ip {
  33.     my \$endereco_ip = shift;
  34.  
  35.     system("iptables -A INPUT -s \$endereco_ip -j DROP");
  36.     print "O IP \$endereco_ip foi bloqueado com sucesso!";
  37. }
  38.  
  39. my \$ip_bloqueado = '192.168.0.123';
  40. bloquear_ip(\$ip_bloqueado);
  41.  
  42. bloquear_conexoes(10, 60);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement