Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Feature request: blob format ('10.0.0.0/23' --> '10.0.0-1.*') #86

Closed
GoogleCodeExporter opened this issue Mar 18, 2015 · 1 comment
Closed

Comments

@GoogleCodeExporter
Copy link

Taken from 
http://stackoverflow.com/questions/6915999/python-convert-list-of-ip-cidr-string
s-to-a-human-readable-glob

In netaddr module (https://github.com/drkjam/netaddr) there are functions that 
convert either an ip range (iprange_to_globs(start, end)), or a CIDR 
(cidr_to_glob(cidr)) to a glob. A glob is a "user friendly form of specifying 
IP address ranges".

>>> import netaddr
>>> ip1 = netaddr.IPNetwork('10.0.0.0/23')
>>> netaddr.cidr_to_glob(ip1)
'10.0.0-1.*'

Also requested, the ability to convert and merge multiple ip address ranges or 
CIDRs into the least amount of globs as possible.

Example 1:

>>> list_of_ips = ['10.0.0.0/23', '10.0.2.0/24', '10.0.3.0/24']
>>> print glob_list(list_of_ips)
'10.0.0-3.*'
Example 2:

>>> list_of_ips2 = ['10.0.0.0/23', '10.0.3.0/24', '10.0.4.0/24']
>>> print glob_list(list_of_ips2)
'10.0.0-1.*, 10.0.3-4.*'
Example 3:

>>> list_of_ips3 = ['10.0.0.0', '10.0.0.3', '10.0.0.4']
>>> print glob_list(list_of_ips2)
'10.0.0.0, 10.0.0.3-4'

Original issue reported on code.google.com by ghe...@gmail.com on 2 Aug 2011 at 7:54

@GoogleCodeExporter
Copy link
Author

globbing addresses like this seems like it's definitely outside of the scope of 
ipaddr. We actually had some functionality similar to this a *long* time ago 
and I pulled it out.

Original comment by pmo...@google.com on 24 Nov 2011 at 10:18

  • Changed state: WontFix

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant