Home > Archive > PERL Modules > April 2005 > Net::Netmask -> match usage problems
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Net::Netmask -> match usage problems
|
|
| ebresie@usa.net 2005-04-14, 3:55 pm |
| Hey guys...I am having some problems which may be a newbie type of
questions but i figured I would ask...
I am using the Net::Netmask module to work with a subnet and try to
identify if a given ip is part of that subnet.
Taking some from
http://www.cpan.org/modules/by-modu...k-1.9007.readme
We have an $subnetIp, and a box $IP. We created a
$subnetIp = "148.1.2.0";
$IP = "148.1.2.3";
$net = new Net::Netmask($subnetIp);
$result = $net->match($IP);
$result += 0;
if ( $result ) {
# Part of the Subnet
} else {
# Not Part of the Subnet
}
Now for some reason, it always returns 0 or false which causes it to
always to run the not part of the subnet code.
What am I doing wrong?
Eric
| |
| Arjen Laarhoven 2005-04-14, 3:55 pm |
| On 2005-04-14, ebresie@usa.net <ebresie@usa.net> wrote:
> Hey guys...I am having some problems which may be a newbie type of
> questions but i figured I would ask...
>
> I am using the Net::Netmask module to work with a subnet and try to
> identify if a given ip is part of that subnet.
>
> Taking some from
>
> http://www.cpan.org/modules/by-modu...k-1.9007.readme
>
> We have an $subnetIp, and a box $IP. We created a
>
> $subnetIp = "148.1.2.0";
> $IP = "148.1.2.3";
> $net = new Net::Netmask($subnetIp);
> $result = $net->match($IP);
> $result += 0;
>
> if ( $result ) {
> # Part of the Subnet
> } else {
> # Not Part of the Subnet
> }
>
> Now for some reason, it always returns 0 or false which causes it to
> always to run the not part of the subnet code.
>
> What am I doing wrong?
You're not telling Net::Netmask what the netmask of the subnet is.
Using either
$subnetIp = "148.1.2.0/24"; # 255.255.255.0
or
$net = new Net::Netmask($subnetIp, "255.255.255.0");
will correct the problem (substitute the right netmask for your
situation, of course).
Arjen
|
|
|
|
|