Skip to content

Add IPv6 functionality to ip module.#28

Merged
itdependsnetworks merged 11 commits into
networktocode:developfrom
dgjustice:dgjustice
Jun 24, 2021
Merged

Add IPv6 functionality to ip module.#28
itdependsnetworks merged 11 commits into
networktocode:developfrom
dgjustice:dgjustice

Conversation

@dgjustice

Copy link
Copy Markdown
Contributor

Adds dual-stack functionality anywhere it was missing. Please see commit comments for more details. The one oddball is cidr_to_netmask because of the ambiguity in translating valid masks <= 32.

- remove redundant call to `str`
- `get_all_host` list to generator to avoid memory overhead of very
large lists
There are only 32 + 128 valid IPv4/6 netmasks, so I created a lookup
table for easy validation.  If there are concerns about the memory
overhead, a computed version is easy enough to implement.
I modified functions where I could to make them compatible with IPv6.
Per [RFC4291](https://datatracker.ietf.org/doc/html/rfc4291#section-4),
I have assumed any addresses in the ::/8 range are IPv4.
The one exception is `cidr_to_netmask`.  I added a v6 version of that
function.
Comment thread netutils/ip.py Outdated
Comment thread netutils/ip.py Outdated
return f"{lower_bound} - {upper_bound}"


def count_bits(i: int) -> int:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a private method?

Also, should avoid using single letter variable names.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up to you.

Comment thread netutils/ip.py

Returns:
list: List of usable IP Addresses within network.
generator: Generator of usable IP Addresses within network.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can go either way on this, performance is obviously better as a generator, but just want to make sure it makes sense for the masses.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can yank this out if you like.

@itdependsnetworks

Copy link
Copy Markdown
Contributor

Thanks!! Mostly just a bunch of nit's, but appreciate the addition.

@itdependsnetworks

Copy link
Copy Markdown
Contributor

Last nit for me, can you remove any single letter variables?

@itdependsnetworks itdependsnetworks merged commit 631a8aa into networktocode:develop Jun 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants