duanshan188866 2012-03-21 19:59
浏览 33

有没有更快的方法来检查PHP块的IP

With my continued battle of blocking spammers from Nigeria I've blocked the country code in my htaccess file using GeoIP but some still manage to get through. To add another layer I want to iterate through the following list of IP ranges from Nigeria and block them:

41.75.192.0 41.75.207.255
41.138.160.0    41.138.191.255
41.139.64.0 41.139.127.255  
41.155.0.0  41.155.127.255
41.184.0.0  41.184.255.255
41.189.0.0  41.189.31.255
41.190.0.0  41.190.31.255
41.203.64.0 41.203.95.255
41.203.96.0 41.203.127.255
41.204.224.0    41.204.255.255
41.205.160.0    41.205.191.255
41.206.0.0  41.206.31.255
41.206.224.0    41.206.255.255
41.211.192.0    41.211.255.255
41.216.160.0    41.216.175.255
41.217.0.0  41.217.127.255
41.219.128.0    41.219.191.255
41.219.192.0    41.219.255.255
41.220.64.0 41.220.79.255
41.221.112.0    41.221.127.255
41.221.160.0    41.221.175.255
62.173.32.0 62.173.63.255
62.193.160.0    62.193.191.255
80.248.0.0  80.248.15.255
80.250.32.0 80.250.47.255
81.18.32.0  81.18.47.255
82.128.0.0  82.128.127.255
195.166.224.0   195.166.255.255 
196.1.176.0 196.1.191.255
196.29.208.0    196.29.223.255
196.45.48.0 196.45.63.255
196.45.192.0    196.45.255.255  
196.200.0.0 196.200.15.255
196.200.64.0    196.200.79.255
196.200.112.0   196.200.127.255 
196.207.0.0 196.207.15.255
196.220.0.0 196.220.31.255
212.100.64.0    212.100.95.255
217.14.80.0 217.14.95.255
217.117.0.0 217.117.15.255

Using the following code to check each range is there a more efficient method or way of doing this?

$range_start = ip2long("41.75.192.0");
$range_end   = ip2long("41.75.207.255");
$ip          = ip2long($_SERVER['REMOTE_ADDR']);
if ($ip >= $range_start && $ip <= $range_end) {
   // blocked
}
  • 写回答

6条回答 默认 最新

  • doucheng4660 2012-03-21 20:04
    关注

    If you have access to .htaccess, you can block them on a configuration level and you don't need to worry about them in scripts.

    order allow,deny
    deny from 41.75.192.0
    deny from 41.75.207.255
    
    ...
    
    deny from 217.117.15.255
    allow from all
    

    Letting Apache keep them out altogether will save you a fair bit of trouble.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度