注:
如果只屏蔽IP 8.8.4.4 則寫(8.8.4.4)
如果只屏蔽IP段8.8.8. 則寫(8.8.8.)
屏蔽多段中間用|隔開,如(8.8.4.4|8.8.8.)
windows2008下 規(guī)則文件web.config (手工創(chuàng)建web.config文件到站點根目錄)
案例一:屏蔽114.102.*.* 代碼如下
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="band ip" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="%{HTTP_X_FORWARDED_FOR}&%{REMOTE_ADDR}&%{HTTP_X_Real_IP}" pattern="(114.102.1|8.8.8.)" />
</conditions>
<action type="AbortRequest" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
案例二:屏蔽某特定IP 114.102.89.23
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="band ip" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="%{HTTP_X_FORWARDED_FOR}&%{REMOTE_ADDR}&%{HTTP_X_Real_IP}" pattern="(114.102.89.23)" />
</conditions>
<action type="AbortRequest" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
案例三:屏蔽IP段:114.102.25.* 代碼如下
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="band ip" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="%{HTTP_X_FORWARDED_FOR}&%{REMOTE_ADDR}&%{HTTP_X_Real_IP}" pattern="(114.102.25.)" />
</conditions>
<action type="AbortRequest" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
windows2003下 規(guī)則文件httpd.conf
請先確保服務(wù)器安裝過偽靜態(tài)組件,然后添加以下規(guī)則。
#Block ip
RewriteCond %{HTTP_X_FORWARDED_FOR}&%{REMOTE_ADDR}&%{HTTP_X_Real_IP} (8.8.4.4|8.8.8.) [NC]
RewriteRule (.*) - [F]
Linux下 規(guī)則文件.htaccess(手工創(chuàng)建.htaccess文件到站點根目錄)
<IfModule mod_rewrite.c>
RewriteEngine On
#Block ip
RewriteCond %{http:X-Forwarded-For}&%{REMOTE_ADDR}&%{http:X-Real-IP} (8.8.4.4|8.8.8.) [NC]
RewriteRule (.*) - [F]
</IfModule>