perl and network addresses

Paul Lussier p.lussier at comcast.net
Mon Mar 27 14:26:01 EST 2006


Hi all,

I'm stumped.  I've got a network address space of 10.0.32/19.  How
ever, this space is carved up using a /16 netmask.  In otherwords, the
/19 netmask was simply used to *allocate* the space from 10.0.32.0 to
10.0.63.255, but we actually *use* the space with a /16 netmask (yes,
this means that 10.0.8.10 is in the *same* physical network as
10.0.33.93!).

Given an address, say 10.0.33.189, I want to get the "network" and
"host" portion of the address.  given that I'm really on a /16, it's
fairly easy to split the IP at 10.0 and 33.189.  However, I want to be
able to do the same thing on the /19 as well.  Once I have the network
and host portions of the address, I need to increment the network
portion by 1 block, then re-apply the host portion.

For example, given the address 10.0.33.189/16:

    Network = 10.0   Host = 33.189
               + 1
             -----
              10.1 + $HOST = 10.1.33.189

And, given the address 10.0.33.189/19:

    Network = 10.0.32   Host = 1.189
                  + 1
                -----
              10.0.64 + $HOST = 10.1.65.189

And, given the address 10.0.35.189/19:
    Network = 10.0.32   Host = 3.189
                  + 1
                -----
              10.0.64 + $HOST = 10.1.67.189

Getting the "next" network block isn't too tough, Net::Netmask does
that for me.  What I can't quite figure out is how to get the host
portion, and then add it to the new network portion.  For a classful
address it's fairly simple, for CIDR address, not so much...

All ideas are welcome and appreciated :)

Thanks,
-- 

Seeya,
Paul



More information about the gnhlug-discuss mailing list