Re: Net::Netmask -> match usage problems



On 2005-04-14, ebresie@xxxxxxx <ebresie@xxxxxxx> 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-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

.



Relevant Pages

  • update(2): boot-image from network-boot server does not apply netmask on V440, doesnt contact gatewa
    ... Rebooting with command: boot ... for ARP/RARP packet Timeout waiting for ARP/RARP packet 4000 ... but then sets an incorrect netmask and thus fails to proceed ... the local subnet to find the Ethernet address of him. ...
    (SunManagers)
  • Re: 2 Nics and default route
    ... >> kernel figures out which interface to use to get to it. ... >> If for some reason you want the cards addressed in the same subnet, ... >> be done by artificially restricting the netmask, ... All machines in the subnet should have the same netmask set and you ...
    (comp.unix.bsd.openbsd.misc)
  • update(3): boot-image from network-boot server does not apply netmask on V440, doesnt contact gatewa
    ... the netmask from the boot-server is not taken: ... RPC-BOOTP FROM BOOT-SERVER ON LOCAL SUBNET, ... Subject: update: boot-image from network-boot server does not apply ...
    (SunManagers)
  • Re: Linux router w/3 nics - need help with routing
    ... netmask and broadcast, or if one leads only to the default gw, it ... under eth0 with 192.168.0.0/24 network is wrong). ... that one to a more limited subnet of your main subnet. ... > then install the route I want. ...
    (comp.os.linux.networking)
  • Re: Subnetting/Routing
    ... >>NITPICKING over netmask number's adds nothing to solve the original ... Which was the Whole point of my original post. ... > the subnet problems. ... Years of schooling to learn a few simple rules.. ...
    (comp.os.linux.networking)