Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Wildcard usage for REMOTE_ADDR comparison

by NetWallah (Monsignor)
on Oct 20, 2012 at 05:34 UTC ( #1000091=note: print w/ replies, xml ) Need Help??


in reply to Re: Wildcard usage for REMOTE_ADDR comparison
in thread Wildcard usage for REMOTE_ADDR comparison

You mean for the "Easy answer" .. yes ..

if ($ENV{REMOTE_ADDR} =~ /^180\.0?76\.0{0,2}6\.\d{1,3}$/) {
(Untested).

             "By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest."           -Confucius


Comment on Re^2: Wildcard usage for REMOTE_ADDR comparison
Download Code
Re^3: Wildcard usage for REMOTE_ADDR comparison
by lostcoder (Initiate) on Oct 20, 2012 at 23:35 UTC
    So... if ($ENV{REMOTE_ADDR} eq '180.76.6.175') { works as if ($ENV{REMOTE_ADDR} =~ /^180\.0?76\.0{0,2}6\.\d{1,3}$/) { what would a wild card for : if ($ENV{REMOTE_ADDR} eq '180.76.6.') { and if ($ENV{REMOTE_ADDR} eq '180.76.') { look like ?
    Sorry if the question sounds so noobish, but the use of wildcards for this particular circumstance is beating up my brain. Technically all I am trying to do is put some code in to my program to keep out various IPs that are able to run my progs in the cgi-bin directory EVEN though their IP is totally banned in the .htaccess file. God only knows why the cgi-bin directory does not benefit from the same protection as all other directories under the .htaccess file as it leaves the progs open to abusive bandwidth consumption.
      The "eq" does not work the same as regular expression pattern matching. The latter is much more powerful.

      Your question:

      what would a wild card for :
      if ($ENV{REMOTE_ADDR} eq '180.76.6.') {
      is not specific enough. The answer depends on what you want to match against.
      For example, to match any digits (actually, between 1 and 3 digits) after the last ".", but require the initial 3 octets to be identical to what is specified, use:
      if ($ENV{REMOTE_ADDR} =~/180\.76\.6\.\d{1,3}/) {
      My previous post shows a somewhat more flexible regular expression that allows but does not require leading zeros in an octet.

      However, as afoken (++) pointed out, this may be too much flexibility if the value you are checking for comes from a "trusted" source, like the CGI module.

                   "By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest."           -Confucius

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1000091]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2014-04-18 11:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (466 votes), past polls