Click here to get back home

Net::Netmask -> match usage problems

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Net::Netmask -> match usage problems ebresie 04-14-2005
Posted by ebresie on April 14, 2005, 10:03 am
Please log in for more thread options


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-module/Net/Net-Netmask-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



Posted by Arjen Laarhoven on April 14, 2005, 6:32 pm
Please log in for more thread options


> 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-module/Net/Net-Netmask-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



Similar ThreadsPosted
Net::NetMask how to find the smallest subnet June 22, 2005, 4:07 am
Text::Diff usage question July 17, 2006, 9:15 am
Audio DSP Usage in primitive sound cards October 18, 2004, 4:55 am
Perl module disk usage, for embedded system. December 5, 2005, 8:38 am
Help with Net::IP::Match and mod_perl September 8, 2004, 8:13 pm
Re: match nested tags May 3, 2006, 5:20 pm
Net::Telnet $prematch, $match April 12, 2007, 10:18 am
DBD::mysql object version 2.9003 does not match bootstrap parameter March 4, 2005, 9:00 am
Problems using GD.pm January 8, 2005, 8:05 pm
Problems when using Net::MSN 1.022 May 4, 2005, 1:20 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap