WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Blocking comments by geography? (6 posts)

  1. mattshepherd
    Member
    Posted 6 years ago #

    Long story short: I've had a stalker for over a decade, nothing legally actionable but a lonnnnng string of annoying phone calls, e-mails, forum posts and blog comments (which is why I'm here) that basically harangue me.

    I've tried eliminating one source of the constant bombardment by putting the first two digits of her IP address in my comments blacklist box on WP, but that doesn't seem to have done anything (I imagine she's got a modem that gets re-assigned a new IP when you power down and back up again).

    I'm wondering if there's any way to block comments by some sort of geographical trackback: the IPs always track back to one company (Sympatico) in one city (Toronto), but the IP changes constantly. Yesterday it was 74.14.112.*; today it's 76.64.48.*. Asterisks there for decency's sake.

    "Regular" spam-tagging doesn't work either -- the person in question just keeps creating new freemail accounts to badger me with.

    Not looking for sympathy, legal advice, or anything else -- I'm well-equipped psychologically, spiritually and legally to deal with this as much as possible -- but it WOULD be helpful if I could configure WP to not accept any comments coming from an IP that tracks back to Sympatico modems or to Toronto, Ontario.

    I don't think anyone else in Toronto would be much bothered by this, but it would eliminate one source of white noise that I have to clean out and delete on a daily basis.

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    How are you tracking her IP addresses to Sympatico in Toronto currently?

    I've seen GeoIP plugins before, but not one to block comments. It's an interesting problem.

  3. mattshepherd
    Member
    Posted 6 years ago #

    For current tracking, I'm taking the IP from the Manage/Comments admin screen and running it through WHOIS.

    I wasn't sure which forum this should be posted in (maybe it's a requested feature?) but this one seemed to be the most "catch-all" for this sort of problem.

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    I'm thinking of a simple solution. If you're basically doing a reverse DNS lookup on her IP and seeing things like "hse-toronto-ppp123824.sympatico.ca", then that may or may not be accurate, but either way it would be possible to block on it.

    This little plugin should block (mark as spam) any IP address that returns "toronto" in a reverse DNS lookup:

    <?php
    /*
    Plugin Name: Block Toronto
    */
    function anti_city($comment) {
    	$comment['user_ip'] = preg_replace( '/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR'] );
    	$hostname = strtolower(gethostbyaddr($comment['user_ip']));
    	if (strpos($hostname, 'toronto')!==FALSE) {
    		add_filter('pre_comment_approved', create_function('$a', 'return \'spam\';'));
    	}
    }
    add_action('preprocess_comment', 'anti_city', 1);
    ?>
  5. mattshepherd
    Member
    Posted 6 years ago #

    Thanks a lot. I'll give it a try. I've saved that as a .php file, uploaded it to the plugin folder, and activated it in the control panel -- that should do it, right?

  6. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Yep. Make sure that you don't have any blank lines at the end of the text file for the plugin however. The ?> should be the absolute end of the file, just like the <?php should be the beginning.

Topic Closed

This topic has been closed to new replies.

About this Topic