in reply to How can I determine whether a URI, hostname or IP address is to the local host machine?

When your script makes an HTTP request, include a header like:

User-Agent: MyScript

In your web server configuration (e.g. Apache .htaccess or httpd.conf) configure the server to block all requests from that user agent.

# This should work in .htaccess SetEnvIf User-Agent MyScript GoAway=1 Order allow,deny Allow from all Deny from env=GoAway

Easy peasy.

use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
  • Comment on Re: How can I determine whether a URI, hostname or IP address is to the local host machine?
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: How can I determine whether a URI, hostname or IP address is to the local host machine?
by dbooth (Novice) on Apr 29, 2014 at 21:42 UTC

    Good idea! However, it is actually a bit more complicated in my case, because my application actually represents several virtual "nodes" (not virtual hosts in the Apache sense) that are effectively making the HTTP requests. I only want to disallow requests from the same host and the same node. So somehow the web server configuration would have to pick up both my application name (MyScript in your example) and the node name from the User-Agent string, and deny access if the the node name matches the applicable part of the URI.

    The downside of this approach is that I don't really want to deny access if the URI is to the local host and same node. It would be much more user friendly if I could instead simply convert the URI to a local file access and avoid issuing the request at all.