Skip to content

IPy forces the user to provide normalized values #68

@SantjagoCorkez

Description

@SantjagoCorkez

Since IPy is a helper library it'd be very good if it does routines itself. Though, you can't provide a non-normalized prefix:

IP('192.156.0.12/24')  # ValueError: IP('192.156.0.12/24') has invalid prefix length (24)

I understand that it's a standard de-facto for prefixes to have their address part be the first address of their range. According to RFC1812:

Internet Address
An assigned number that identifies a host in an internet. It
has two parts: an IP address and a prefix length. The prefix
length indicates how many of the most specific bits of the
address constitute the network

So, if a library's user wants a prefix (by providing a mask along with an IP address to constructor) it would be great if IPy do the Network Address construction by itself, not enforcing a user do the same calculations as IPy does under the hood.

For example, a user has an IP as a string 192.168.99.230

The user wants to check, if another IP 192.168.99.126 belong to the same /25 network. In order to do this a user needs to construct a network address (all 7 last bits dropped to 0) for both (hence, take an integer equivalent) and then compare. By the time a user has ints and a mask, he does not need IPy at all any more.

Instead of raising, IPy could provide a user with functionality like this:

>>> ip1 = IPy.IP('192.168.99.230/25')
>>> ip1
<<< IP('192.168.99.128/25')
>>> ip2 = IPy.IP('192.168.99.126/25')
>>> ip2
<<< IP('192.168.99.0/25')
>>> ip1 == ip2
<<< False

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions