IPv4 range (start & finish) to slash notation

39 views
Skip to first unread message

Parag Baxi

unread,
Jul 14, 2011, 1:25:13 PM7/14/11
to ipaddr-py-dev
Is it possible to use ipaddr to convert a starting and ending IP
address to a slash notation?

Example:
Input = 10.182.71.0-10.182.75.255
Output = 10.182.71.0/24, 10.182.72.0/22

Matthew Flanagan

unread,
Jul 15, 2011, 2:25:54 AM7/15/11
to ipaddr-py-dev
Hi Parag,

Yes this is very easy to do:

>>> from ipaddr import IPAddress, summarize_address_range
>>> summarize_address_range(IPAddress('10.182.71.0'), IPAddress('10.182.75.255'))
[IPv4Network('10.182.71.0/24'), IPv4Network('10.182.72.0/22')]


It works for IPv6 as well.

cheers

Matthew
Reply all
Reply to author
Forward
0 new messages