昨天写了个Filter!

昨天写了个Filter!

昨天看了看自己的资源存放站点,发现当机了,很奇怪:都是静态的东西怎么会当机?

看了看日志,NND,日志10几个G,再仔细看,都是一个IP发请求,获得一个文件,每秒4次,可怜我的TOMCAT,怎么撑得住这么搞?

再仔细想,不对啊!下一个文件只是一个请求即可,着明显是恶意攻击!

没办法,写了个Filter,只允许校内访问。

列举如下,备忘。

---------------------

package me;

/*

 * Author: Elpout

 * DateTime: 2008-06-18 17:46

 * Lisence: Just You Like!

 *

*/

import java.io.IOException;

import javax.servlet.*;

import javax.servlet.http.*;



public class IPFilter implements Filter {



    protected FilterConfig filterConfig = null;

    protected String[] AIP = null;

    protected String AllowedIP = null;

    protected String ErrorPage = null;





    public void destroy() {

        this.filterConfig = null;

    	}



    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) 

	    throws IOException, ServletException {

         

	HttpServletRequest req = (HttpServletRequest) request;

    	HttpServletResponse resp = (HttpServletResponse) response;

	

	Boolean Flag = false;

	String cip=req.getRemoteHost();



	for (String TB:AIP){

		if (cip.startsWith(TB)) {

		       	Flag = true;

			break;

			}	

		}

	if (Flag)

     		chain.doFilter(request, response);

	else

        	 resp.sendRedirect (this.ErrorPage);

    	}



    public void init(FilterConfig filterConfig) throws ServletException {



        this.filterConfig = filterConfig;

        this.AllowedIP = filterConfig.getInitParameter("AllowedIP");

        this.ErrorPage = filterConfig.getInitParameter("RePage");

        this.AIP = AllowedIP.split(";");

	

      	}











}
源码及Class&web.xml下载:http://onpm.net/im/IPFilter.rar
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值