【问题标题】:Can I ban or restrict a country based on IP?我可以根据 IP 禁止或限制一个国家/地区吗?
【发布时间】:2012-01-06 11:08:34
【问题描述】:

我从非洲的尼日利亚和加纳等地获得了 6 到 10 个注册。我目前正在捕获 IP,因此是否可以限制来自特定国家/地区的一系列 IP?

如果我可以限制它们,是否将此范围添加到我的 .htaccess 文件或在站点级别限制它们更有意义?

【问题讨论】:

    标签: php .htaccess mod-rewrite spam-prevention


    【解决方案1】:

    使用 Apache 的 mod_geoip:

    GeoIP启用 GeoIPDBFile /path/to/GeoIP.dat SetEnvIf GEOIP_COUNTRY_CODE US BlockCountry # ... 在此处放置更多国家/地区 拒绝来自 env=BlockCountry

    【讨论】:

      【解决方案2】:

      可以获取maxmind数据库:

      http://www.maxmind.com/app/mod_geoip

      并使用此代码:

      GeoIPEnable On
      GeoIPDBFile /path/to/GeoIP.dat
      
      # Redirect multiple countries to a single page
      RewriteEngine on
      RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(NI|GH)$
      RewriteRule ^(.*)$ - [F]
      

      【讨论】:

        【解决方案3】:

        只需 google 即可获得 GEOIP - 有许多免费服务可用,您还可以获取包含国家特定 IP 模式的文件。没有任何服务可以为您提供 100% 的保护,因为您可以伪造 IP。

        【讨论】:

          【解决方案4】:

          【讨论】:

          • 谢谢,我也刚刚发现:countryipblocks.net 有没有人用过这个并且运气好?看起来是免费的。
          猜你喜欢
          • 1970-01-01
          • 2012-02-18
          • 1970-01-01
          • 2017-08-28
          • 1970-01-01
          • 2015-01-07
          • 1970-01-01
          • 2020-02-27
          • 1970-01-01
          相关资源
          最近更新 更多