This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ipaddress.IPv4network.interfaces()
Type: enhancement Stage: test needed
Components: Library (Lib) Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: andrei.avk, eric.smith, ncoghlan, terry.reedy, wyko.ter.haar
Priority: normal Keywords:

Created on 2020-11-26 23:35 by wyko.ter.haar, last changed 2022-04-11 14:59 by admin.

Messages (8)
msg381921 - (view) Author: Wyko ter Haar (wyko.ter.haar) Date: 2020-11-26 23:35
It would be really nice if we could get an iterator just like ip_network.hosts() that iterates over the interfaces in a subnet.
msg381927 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-11-27 02:18
I'm not sure what you mean by iterating over the interfaces in a subnet. Could you give an example?
msg381932 - (view) Author: Wyko ter Haar (wyko.ter.haar) Date: 2020-11-27 09:04
Literally just the same thing as .hosts(), except outputting interface
objects instead of addresses. Maybe it could be a flag in .hosts() instead,
something like "cast_as_interface".

Sincerely,

Wyko ter Haar

On Fri, Nov 27, 2020, 3:18 AM Eric V. Smith <report@bugs.python.org> wrote:

>
> Eric V. Smith <eric@trueblade.com> added the comment:
>
> I'm not sure what you mean by iterating over the interfaces in a subnet.
> Could you give an example?
>
> ----------
> nosy: +eric.smith
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue42478>
> _______________________________________
>
msg381934 - (view) Author: Wyko ter Haar (wyko.ter.haar) Date: 2020-11-27 09:14
>>> X = ip_network("10.0.0.0/24")
>>> H= X.hosts(as_interfaces= True)
>>> next(H)
IPv4Interface('10.0.0.0/24')
>>> next(H)
IPv4Interface('10.0.0.1/24')

Something like that. Sure, I could cast the output of hosts as an
interface, but then it would be missing the netmask.

Sincerely,

Wyko ter Haar

On Fri, Nov 27, 2020, 10:04 AM Wyko ter Haar <report@bugs.python.org> wrote:

>
> Wyko ter Haar <wyko.ter.haar@gmail.com> added the comment:
>
> Literally just the same thing as .hosts(), except outputting interface
> objects instead of addresses. Maybe it could be a flag in .hosts() instead,
> something like "cast_as_interface".
>
> Sincerely,
>
> Wyko ter Haar
>
> On Fri, Nov 27, 2020, 3:18 AM Eric V. Smith <report@bugs.python.org>
> wrote:
>
> >
> > Eric V. Smith <eric@trueblade.com> added the comment:
> >
> > I'm not sure what you mean by iterating over the interfaces in a subnet.
> > Could you give an example?
> >
> > ----------
> > nosy: +eric.smith
> >
> > _______________________________________
> > Python tracker <report@bugs.python.org>
> > <https://bugs.python.org/issue42478>
> > _______________________________________
> >
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue42478>
> _______________________________________
>
msg381935 - (view) Author: Wyko ter Haar (wyko.ter.haar) Date: 2020-11-27 09:16
Starting at .1, not .0.

Sincerely,

Wyko ter Haar

On Fri, Nov 27, 2020, 10:14 AM Wyko ter Haar <wyko.ter.haar@gmail.com>
wrote:

> >>> X = ip_network("10.0.0.0/24")
> >>> H= X.hosts(as_interfaces= True)
> >>> next(H)
> IPv4Interface('10.0.0.0/24')
> >>> next(H)
> IPv4Interface('10.0.0.1/24')
>
> Something like that. Sure, I could cast the output of hosts as an
> interface, but then it would be missing the netmask.
>
> Sincerely,
>
> Wyko ter Haar
>
> On Fri, Nov 27, 2020, 10:04 AM Wyko ter Haar <report@bugs.python.org>
> wrote:
>
>>
>> Wyko ter Haar <wyko.ter.haar@gmail.com> added the comment:
>>
>> Literally just the same thing as .hosts(), except outputting interface
>> objects instead of addresses. Maybe it could be a flag in .hosts()
>> instead,
>> something like "cast_as_interface".
>>
>> Sincerely,
>>
>> Wyko ter Haar
>>
>> On Fri, Nov 27, 2020, 3:18 AM Eric V. Smith <report@bugs.python.org>
>> wrote:
>>
>> >
>> > Eric V. Smith <eric@trueblade.com> added the comment:
>> >
>> > I'm not sure what you mean by iterating over the interfaces in a subnet.
>> > Could you give an example?
>> >
>> > ----------
>> > nosy: +eric.smith
>> >
>> > _______________________________________
>> > Python tracker <report@bugs.python.org>
>> > <https://bugs.python.org/issue42478>
>> > _______________________________________
>> >
>>
>> ----------
>>
>> _______________________________________
>> Python tracker <report@bugs.python.org>
>> <https://bugs.python.org/issue42478>
>> _______________________________________
>>
>
msg381998 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-11-28 12:54
Wyko, when responding by email, please delete the message you are responding to, as it is redundant when posted to the web page.
msg381999 - (view) Author: Wyko ter Haar (wyko.ter.haar) Date: 2020-11-28 12:55
You bet. Totally forgot when I was replying on my phone :)
msg397732 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2021-07-17 21:14
Related (with PR up): https://bugs.python.org/issue42861
History
Date User Action Args
2022-04-11 14:59:38adminsetgithub: 86644
2021-07-17 21:14:40andrei.avksetnosy: + andrei.avk
messages: + msg397732
2020-11-28 12:55:41wyko.ter.haarsetmessages: + msg381999
2020-11-28 12:55:11terry.reedysetcomponents: + Library (Lib)
2020-11-28 12:54:56terry.reedysetversions: + Python 3.10, - Python 3.9
nosy: + terry.reedy, ncoghlan

messages: + msg381998

stage: test needed
2020-11-27 09:16:07wyko.ter.haarsetmessages: + msg381935
2020-11-27 09:14:41wyko.ter.haarsetmessages: + msg381934
2020-11-27 09:04:25wyko.ter.haarsetmessages: + msg381932
2020-11-27 02:18:36eric.smithsetnosy: + eric.smith
messages: + msg381927
2020-11-26 23:35:44wyko.ter.haarcreate