復制代碼 代碼如下:
$real_ip = getenv('HTTP_X_FORWARDED_FOR');
if(isset($real_ip)){
shell_exec("echo $real_ip > real_ip.txt");
shell_exec("echo $_SERVER['REMOTE_ADDR']> proxy.txt");
}else{
shell_exec("echo $_SERVER['REMOTE_ADDR'] > ips.txt")"
}
echo'服務器受到攻擊,正在收集攻擊源,請在5分鐘后訪問本站,5分鐘內多次訪問本站有可能會被當作攻擊源封掉IP。謝謝合作!';
?>
復制代碼 代碼如下:
rewrite (.*) /ip.php;
Lighttpd規則:
url.rewrite = (
"^/(.+)/?$" => "/ip.php"
)
復制代碼 代碼如下:
$threshold = 10;
$ips = array_count_values(file('ips.txt'));
$ban_num = 0;
foreach($ips as $ip=>$num){
if($num > $threshold){
$ip = trim($ip);
$cmd = "iptables -I INPUT -p tcp --dport 80 -s $ip -j DROP";
shell_exec($cmd);
echo "$ip baned! ";
$ban_num ++;
}
}
$proxy_arr = array_unique(file('ips.txt'))'
foreach($proxy_arr as $proxy){
$proxy = trim($proxy);
$cmd = "iptables -I INPUT -p tcp --dport 80 -s $ip -j DROP";
shell_exec($cmd);
echo "$ip baned! ";
$ban_num ++;
}
echo "total: $ban_num ips ";
?>
新聞熱點
疑難解答