Thu Aug 30 13:42:25 2012: Request 79310 was acted upon.
Transaction: Ticket created by [email protected]
Queue: PAR
Subject: Request for Perl Code
Broken in: (no value)
Severity: (no value)
Owner: Nobody
Requestors: [email protected]
Status: new
Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=79310 >
Dear Sir,
Check if IP address is in the range 172.125.1.0 and 172.125.25.0 using only
return functions & regular expressions in Perl. Do not use parse functions.
For this question, my code is:
#!/usr/bin/perl
print "Content-type:text/html\n\n";
my $ipaddr= "172.125.7.0";
chomp($ipaddr);
my $pattern='^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$';
if($ipaddr=~m/$pattern/)
{
if (($1<172 || $2<125 || $3<1 || $4<0) || ($1>172 || $2>125 || $3>25 ||
$4>0))
{
print "$ipaddr is not in the range between IP Address 172.125.1.0 and
172.125.25.0";
}
else
{
print "$ipaddr is a valid IP Address";
}
}
else
{
print "$ipaddr is an Invalid IP Address";
}
But I am going wrong in the regular expression.
Please help.
Thanks&Regards,
Ashwin