Advertisement
w3tools_info

Anti-DDoS PHP Script (Base)

Dec 21st, 2011
7,562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.00 KB | None | 0 0
  1. <?php
  2. /*
  3. Posted @ http://www.w3tools.info/2011/12/anti-ddos-php-script.html
  4. */
  5.  
  6.  $ Ad_ddos_query = 10, / / ​​number of requests per second to detect DDOS attacks
  7.  $ Ad_check_file = 'check.txt'; / / file to write the current state during the monitoring
  8.  $ Ad_temp_file = 'all_ip.txt'; / / temporary file
  9.  $ Ad_black_file = 'black_ip.txt'; / / will be entered into a zombie machine ip
  10.  $ Ad_white_file = 'white_ip.txt'; / / ip logged visitors
  11.  $ Ad_dir = 'anti_ddos'; / / directory with scripts
  12.  $ Ad_num_query = 0, / / ​​current number of requests per second from a file $ check_file
  13.  $ Ad_sec_query = 0, / / ​​second from a file $ check_file
  14.  $ Ad_end_defense = 0, / / ​​end while protecting the file $ check_file
  15.  $ Ad_sec = date ("s"); / / current second
  16.  $ Ad_date = date ("mdHis"); / / current time
  17.  $ Ad_defense_time = 10000 / / ddos ​​attack detection time in seconds at which stops monitoring
  18.  
  19.  
  20.  
  21.  if (! file_exists ("{$ ad_dir} / {$ ad_check_file}") or! file_exists ("{$ ad_dir} / {$ ad_temp_file}") or! file_exists ("{$ ad_dir} / {$ ad_black_file}") or ! file_exists ("{$ ad_dir} / {$ ad_white_file}") or! file_exists ("{$ ad_dir} / anti_ddos.php")) {
  22.  die ("Not enough files.");
  23.  }
  24.  
  25.  require ("{$ ad_dir} / {$ ad_check_file}");
  26.  
  27.  if ($ ad_end_defense and $ ad_end_defense> $ ad_date) {
  28.  require ("{$ ad_dir} / anti_ddos.php");
  29.  } Else {
  30.  if ($ ad_sec == $ ad_sec_query) {
  31.  $ Ad_num_query + +;
  32.  } Else {
  33.  $ Ad_num_query = '1 ';
  34.  }
  35.  
  36.  if ($ ad_num_query> = $ ad_ddos_query) {
  37.  $ Ad_file = fopen ("{$ ad_dir} / {$ ad_check_file}", "w");
  38.  $ Ad_end_defense = $ ad_date + $ ad_defense_time;
  39.  $ Ad_string = '<? Php $ ad_end_defense ='. $ Ad_end_defense. ';?>';
  40.  fputs ($ ad_file, $ ad_string);
  41.  fclose ($ ad_fp);
  42.  } Else {
  43.  $ Ad_file = fopen ("{$ ad_dir} / {$ ad_check_file}", "w");
  44.  $ Ad_string = '<? Php $ ad_num_query ='. $ Ad_num_query. '; $ Ad_sec_query ='. $ Ad_sec. ';?>';
  45.  fputs ($ ad_file, $ ad_string);
  46.  fclose ($ ad_fp);
  47.  }
  48.  }
  49.  ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement