Restrict IP access to a Perl application



Dear all:

I am a newbie to Perl and have an application written in Perl. I put
IPs that are "allowed" to access the application into a file called
"ip.allow".

I then tried to compare the $ENV{REMOTE_ADDRESS} to the IPs in
"ip.allow" to determine the access right which looks like the
following:

10.0.0.1
10.0.0.2
10.0.0.3

And the code is:

$address=$ENV{'REMOTE_ADDR'};

open(FILE,"/path/to/ip.allow") or die ("Cannot open file!");
flock(FILE,2);
while ($line=<FILE>) {
$line=~s/\./\\\./g;
if ($line =~ /$address/) {
print "IP matched!!\n";
last;
}
}
flock(FILE,8);
close(FILE);

But it doesn't seem to work because when I take out 10.0.0.1 from the
ip.allow file, 10.0.0.1 can still access the application.

Any suggestions are appreciated, thanks.

barramundi9
.



Relevant Pages

  • Re: Restrict IP access to a Perl application
    ... barramundi9 wrote on VCCLXV September MCMXCIII ... I am a newbie to Perl and have an application written in Perl. ... IPs that are "allowed" to access the application into a file called ... In fact, I find it odd that, assuming $ENV ...
    (comp.lang.perl.misc)
  • Re: Restrict IP access to a Perl application
    ... I am a newbie to Perl and have an application written in Perl. ... IPs that are "allowed" to access the application into a file called ... That seems odd. ... In fact, I find it odd that, assuming $ENV ...
    (comp.lang.perl.misc)
  • Re: LWP::UserAgent and non-default outgoing IP
    ... Quoth Tomek: ... My box on which Perl runs has several IPs, ... "Awww, ...
    (comp.lang.perl.misc)
  • Re: Using perl in a Bash-script to extract IP-addresses?
    ... I need to extract those IPs & ranges, ... I've read that Perl is "best" for Text ... assign the comma-separated list to a variable in that Bash script. ...
    (perl.beginners)
  • Re: Restrict IP access to a Perl application
    ... I am a newbie to Perl and have an application written in Perl. ... IPs that are "allowed" to access the application into a file called ... You can just compare strings, no need for the regexp ...
    (comp.lang.perl.misc)