php ddos 安全处理代码
<?php
//查询禁止IP
$ip =$_SERVER['REMOTE_ADDR'];
$fileht=".htaccess2";
if(!file_exists($fileht))file_put_contents($fileht,"");
$filehtarr=@file($fileht);
if(in_array($ip."\r\n",$filehtarr))die("Warning:"."<br>"."Your IP address are forbided by some reason, IF you have any question Pls emill to shop@mydalle.com!");
//加入禁止IP
$time=time();
$fileforbid="log/forbidchk.dat";
if(file_exists($fileforbid))
{ if($time-filemtime($fileforbid)>60)unlink($fileforbid);
else{
$fileforbidarr=@file($fileforbid);
if($ip==substr($fileforbidarr[0],0,strlen($ip)))
{
if($time-substr($fileforbidarr[1],0,strlen($time))>600)unlink($fileforbid);
elseif($fileforbidarr[2]>600){file_put_contents($fileht,$ip."\r\n",FILE_APPEND);unlink($fileforbid);}
else{$fileforbidarr[2]++;file_put_contents($fileforbid,$fileforbidarr);}
}
}
}
//防刷新
$str="";
$file="log/ipdate.dat";
if(!file_exists("log")&&!is_dir("log"))mkdir("log",0777);
if(!file_exists($file))file_put_contents($file,"");
$allowTime = 120;//防刷新时间
$allowNum=10;//防刷新次数
$uri=$_SERVER['REQUEST_URI'];
$checkip=md5($ip);
$checkuri=md5($uri);
$yesno=true;
$ipdate=@file($file);
foreach($ipdate as $k=>$v)
{ $iptem=substr($v,0,32);
$uritem=substr($v,32,32);
$timetem=substr($v,64,10);
$numtem=substr($v,74);
if($time-$timetem<$allowTime){
if($iptem!=$checkip)$str.=$v;
else{
$yesno=false;
if($uritem!=$checkuri)$str.=$iptem.$checkuri.$time."1\r\n";
elseif($numtem<$allowNum)$str.=$iptem.$uritem.$timetem.($numtem+1)."\r\n";
else
{
if(!file_exists($fileforbid)){$addforbidarr=array($ip."\r\n",time()."\r\n",1);file_put_contents($fileforbid,$addforbidarr);}
file_put_contents("log/forbided_ip.log",$ip."--".date("Y-m-d H:i:s",time())."--".$uri."\r\n",FILE_APPEND);
$timepass=$timetem+$allowTime-$time;
die("Warning:"."<br>"."Sorry,you are forbided by refreshing frequently too much, Pls wait for ".$timepass." seconds to continue!");
}
}
}
}
if($yesno) $str.=$checkip.$checkuri.$time."1\r\n";
file_put_contents($file,$str);
?>
php ddos 安全处理代码的更多相关文章
- Linux DDos防御
今天要说的就是一款能够自动屏蔽DDOS攻击者IP的软件:DDoS deflate. DDoS deflate介绍 DDoS deflate是一款免费的用来防御和减轻DDoS攻击的脚本.它通过netst ...
- 《UNIX/Linux网络日志分析与流量监控》新书发布
本书从UNIX/Linux系统的原始日志(Raw Log)采集与分析讲起,逐步深入到日志审计与计算机取证环节.书中提供了多个案例,每个案例都以一种生动的记事手法讲述了网络遭到入侵之后,管理人员开展系统 ...
- 《Unix/Linux日志分析与流量监控》书稿完成
<Unix/Linux日志分析与流量监控>书稿完成 近日,历时3年创作的75万字书稿已完成,本书紧紧围绕网络安全的主题,对各种Unix/Linux系统及网络服务日志进行了全面系统的讲解,从 ...
- 【安全开发】Android安全编码规范
申明:本文非笔者原创,原文转载自:https://github.com/SecurityPaper/SecurityPaper-web/blob/master/_posts/2.SDL%E8%A7%8 ...
- $2015 武汉森果公司web后端开发实习日记----书写是为了更好的思考
找暑期实习,3月份分别投了百度和腾讯的实习简历,都止步于笔试,总结的主要原因有两点:基础知识不扎实,缺乏项目经验.后来到拉勾网等网站上寻找实习,看了很多家,都还是处于观望状态.后来参加了武汉实习吧在大 ...
- php防止ddos,dns,集群攻击的实现代码
<?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +-------------------------------------- ...
- c#DDOS代码
//在工程属性中设置"允许不安全代码"为true ?using System; using System.Net; using System.Net.Sockets; using ...
- PHP DDOS的UDP攻击,TCP攻击,和CC攻击的核心代码
网络安全向,请勿用作非法用途 CC攻击模块: <?phpecho “状态 : 正常运行中…..<br>”;echo “================================ ...
- php--防止DDos攻击代码
<?php //查询禁止IP $ip =$_SERVER['REMOTE_ADDR']; $fileht=".htaccess2"; if(!file_exists($fil ...
随机推荐
- Linux查看内存占用情况
输入:top PID 进程的ID USER 进程所有者 PR 进程的优先级别,越小越优先被执行 Ninice 值 VIRT 进程占用的虚拟内存 RES 进程占用的物理内存 SHR 进程使用的共享内存 ...
- java三大框架介绍
常听人提起三大框架,关于三大框架,做了如下了解: 三大框架:Struts+Hibernate+Spring java三大框架主要用来做WEN应用. Struts主要负责表示层的显示 Spring利用它 ...
- Android - service and thread
服务(Service)是Android中实现后台程序运行的方案.适合执行那些不需要和用户交互并长期执行的任务. 服务并非运行在一个独立的进程中,而是依赖于创建服务时所在的应用程序.当某个应用程序进程被 ...
- Windows 10 IoT Serials 9 – 如何利用IoTCoreAudioControlTool改变设备的音频设备
大家知道,在Windows 10 IoT Core上,如果用户外接了USB声卡.带有麦克风的摄像头之类的硬件,就会有多个音频设备可以用.但是,系统目前并没有提供直接的UI来设置音频的输入或者输出设备. ...
- (转)HTTP 协议详解(基础)
HTTP 协议详解 作者: 小坦克 来源: 博客园 发布时间: 2012-02-14 13:32 阅读: 95523 次 推荐: 99 原文链接 [收藏] 相关文章:HTTP 协议 ...
- FaceRank-人脸打分基于 TensorFlow 的 CNN 模型
FaceRank-人脸打分基于 TensorFlow 的 CNN 模型 隐私 因为隐私问题,训练图片集并不提供,稍微可能会放一些卡通图片. 数据集 130张 128*128 张网络图片,图片名: 1- ...
- 根据百度,gps坐标获取天气
楼主用的是阿里天气免费版,限制1000次,可以重复购买 下面放代码 var orgWindow = new OrganizeWindowProxy(WorkContext); var orgInfo ...
- EF 中 Code First 的数据迁移以及创建视图
写在前面: EF 中 Code First 的数据迁移网上有很多资料,我这份并没什么特别.Code First 创建视图网上也有很多资料,但好像很麻烦,而且亲测好像是无效的方法(可能是我太笨,没搞成功 ...
- Warning[w2]: Symbol ?P…
屏蔽的方法: 一.找到$PROJ_DIR$\..\..\..\Tools\CC2530DB\f8w2530.xcl位置 二.找到f8w2530.xcl 三.打开f8w2530.xcl,注释D?PBAN ...
- HDU 6033 Add More Zero (数学)
Description There is a youngster known for amateur propositions concerning several mathematical hard ...