You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.
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
The text was updated successfully, but these errors were encountered:
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 freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Original issue reported on code.google.com by
ghe...@gmail.com
on 2 Aug 2011 at 7:54The text was updated successfully, but these errors were encountered: