Fwd: Is there a function of ipaddress to get the subnet only from input like 192.168.1.129/25
Nathan Hilterbrand
nhilterbrand at gmail.com
Tue Oct 17 17:28:57 EDT 2017
Absolutely, Stefan! I like yours a lot better. I am an old perl hack that
is still learning the ins and outs of Python, and this is just the sort of
thing that I like to see.
Thanks!
On Tue, Oct 17, 2017 at 4:19 PM, Stefan Ram <ram at zedat.fu-berlin.de> wrote:
> Nathan Hilterbrand <nhilterbrand at gmail.com> writes:
> >I may have misunderstood what you were looking for, but went ahead and
> >cobbled this ugly function together. Takes a string like "
> 192.168.1.128/25"
> >as input, and returns the subnet address. Just slapped together, so not
> >the most robust thing in the world
>
> The IP address of the OP has some so-called "host bits" set.
> Therefore, it might not be considered to be a valid subnet
> specification by some parties.
>
> Your code seems to have the intention to remove those
> disturbing host bits. You did this using a bit mask.
> It might also be possible to accomplish the same by
> a right shift plus a left shift, e.g.,
>
> |>>> IPv4Address( int( IPv4Address( '192.168.1.129' ))>> 25 << 25 )
> |IPv4Address('192.0.0.0')
>
> .
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list