How to block someones IP address?

by 29 comments
HI,

I have been getting junk emails from automated bots on my website's form. I have installed a captcha and that worked for a while but a few days ago I started getting those annoying emails again.

I have the senders IP address. Is there a way to block the spammers IP address? My host is Yahoo and Yahoo does not support .htaccess.
(Trying to change hosting soon)

Is there a way to block the IP without using .htaccess?
#programming #address #block #email #ipaddress #someones #spam
  • Profile picture of the author Nathan K
    Add this line on top of your header file, and enter the ipaddress.

    <?php
    $deny = array("000.000.000","000.000.001");
    if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
    header("location: http://www.google.com/");
    exit();
    }
    ?>
    • Profile picture of the author sonzoy
      if your host is not supporting .htaccess then use Nathan K PHP script otherwise changing the host will be always an advantage ....
  • Profile picture of the author Kingfish85
    Originally Posted by Ani86 View Post

    HI,

    I have been getting junk emails from automated bots on my website's form. I have installed a captcha and that worked for a while but a few days ago I started getting those annoying emails again.

    I have the senders IP address. Is there a way to block the spammers IP address? My host is Yahoo and Yahoo does not support .htaccess.
    (Trying to change hosting soon)

    Is there a way to block the IP without using .htaccess?
    1. The IP's will most likely always be different.

    2. Yahoo doesn't support htaccess......yea, it's time to find a "real" web host.
    • Profile picture of the author Ani86
      They say that they support htaccess.txt not .htaccess

      you think this will work if i use htaccess.txt ?
  • Profile picture of the author chrislim2888
    Personally, I'm not recommend the blocking at page level. Therefore, if possible change the hosting will be an option to consider, for long term solution.
    • Profile picture of the author Ani86
      I called yahoo again they said .htaccess is same as their htacess.txt they dont put the (.) in the beginning but instead they use .txt the tech guy said its the same thing.

      Now how can I block the IP address in the htaccess file. does anyone know how to write the code for that?

      and I'd like to learn more about Nathan K's code. anyone got a link that explains the code?

      I wrote this code but not sure if its correct or not

      <Limit GET>
      order allow,deny
      deny from 10.20.30
      deny from 192.168.207.154
      allow from all
      </Limit>
  • Profile picture of the author kyoo
    That should do it, although I haven't tested this snippet of code, there may be typos etc. Nathan K probably pulled it from someplace where it was working.
  • Profile picture of the author webzie
    Blocking him from your website would be hard, because all he needs to do is use a proxy to disguise his IP.. But you can block it from control panel of your hosting
    • Profile picture of the author Ani86
      Originally Posted by webzie View Post

      Blocking him from your website would be hard, because all he needs to do is use a proxy to disguise his IP.. But you can block it from control panel of your hosting
      How do i block from hosting? my hosting is 1and1
  • Profile picture of the author CrazyStyle
    Code:
    <?php
    if($_SERVER['REMOTE_ADDR'] == 'xx.xx.xx.xxx'){
            die("Go to hell.");
    }
    ?>
  • Profile picture of the author webisland
    You can write rewrite rules or you can write php or any serverside script to block ip address or country
  • Profile picture of the author WriteArm
    Ani 86 : Have you tried just using IP deny in the cpanel?
  • Profile picture of the author DAVE49
    Here you can find all information about your IP
  • Profile picture of the author project1010
    If you have programmatic control over your website, then you can block an IP address. For example, in VBScript for ASP,
    <%
    if ( request.servervariables ("remote_host") = "XXX.XXX.XXX.XXX") then response.redirect "http://www.google.com"
    %>

    where XXX.XXX.XXX.XXX is his IP address.
  • Profile picture of the author Kingfish85
    junk emails from automated bots

    This means the IP addressed CHANGE....they CHANGE = not the same.

    Adding code to the htaccess is NOT going to do anything here....do you people even read the thread before commenting with useless rpelies?!

    You need to use something like CloudFlare or a host that has a better firewall or WAF.
  • Profile picture of the author buysellbrowse
    Since you have a website form visible from anywhere in the world, blocking a few IPs will not help much. You need a better captcha system that hasn't been broken yet, preferably something that requires the user to understand instructions, then move an object with the mouse to complete a task. Eye-hand coordination is something a computer cannot do (yet).
  • Profile picture of the author Roy Jones
    You can block an IP Address using IPSec

    STEP 1:
    Click on Start menu, then click on Run

    STEP 2:
    Type " secpol.msc" and Click OK

    STEP 3:
    When the Local Security Settings console opens, Click on "IP security policies on Local computer"
    • Profile picture of the author shahriyar
      I receive a lot of spam every day on my sites, blocking IPs is a solution but not a good one. Because spam will come all kinds of different IPs, they never stay the same.

      You should focus on improving security on your forms. Have you tried using reCaptcha? http://www.google.com/recaptcha
  • Profile picture of the author nettiapina
    As others have suggested, blocking IPs to combat spam is futile. If someone is in that kind of business, they wont hesitate to proxy around your blocks.

    The IP addresses in the htaccess code weren't the ones you're trying to block, right? They're not public IP addresses.
  • Profile picture of the author RobinInTexas
    It's going to take a while, but I am using Wordfence plugin on WordPress sites and blocking any and all bots I see with the exception of Google, Bing and Yahoo.
    Also blocking ip ranges for any web hosts I find.

    Starting to look into using CloudFlare to fence them out far away from my hosting accounts.
  • Profile picture of the author kpmedia
    I send mine to a honeypot.
  • Profile picture of the author wondy
    Let me riddle you this: if normal users are allowed to submit the form, how are you going to stop spammers from doing the same?

    You can't filter them out at the web level completely. Spammers can always just fill out the CAPTCHA themselves. What you need to do is install a reliable spam filter on your email server.
  • Profile picture of the author jkujami
    You can use this service to prevent any country or ip's from accessing your websites.

    MyIPBlocker - IP BLOCKER | COUNTRY BLOCKER

    Configure it properly and add a line to your page/s. It will do the rest for you. You can redirect the blocked traffic wherever you want as well and no need for .htcacess

Next Topics on Trending Feed