Re: Restrict IP access to a Perl application
- From: Dave Weaver <zen13097@xxxxxxxxx>
- Date: 30 Jan 2008 08:26:02 GMT
barramundi9 <barramundi9@xxxxxxxxxxx> wrote:
open(FILE,"/path/to/ip.allow") or die ("Cannot open file!");
flock(FILE,2);
while ($line=<FILE>) {
$line=~s/\./\\\./g;
You replace '.' with '\.' in $line...
if ($line =~ /$address/) {
....so now you're matching: "10\\.0\\.0\\.1\n' =~ /10.0.0.1/
which obviously fails since there are no backslashes in $address.
I suspect you meant this to be:
if ( $address =~ /$line/ ) {
which would still fail since there is no "\n" in $address.
In which case you could use chomp and also get rid of the s///
and use \Q in your match:
chomp $line;
if ( $address =~ /\Q$line/ ) {
or, better yet, use chomp() and eq
chomp $line;
if ( $line eq $address ) {
.
- References:
- Restrict IP access to a Perl application
- From: barramundi9
- Restrict IP access to a Perl application
- Prev by Date: FAQ 9.18 How do I decode a MIME/BASE64 string?
- Next by Date: Re: Restrict IP access to a Perl application
- Previous by thread: Re: Restrict IP access to a Perl application
- Next by thread: Re: Restrict IP access to a Perl application
- Index(es):