Skip to content

Instantly share code, notes, and snippets.

@SilvM
Last active September 26, 2018 03:55
Show Gist options
  • Save SilvM/325c4754b83ea91fffe553530bb87451 to your computer and use it in GitHub Desktop.
Save SilvM/325c4754b83ea91fffe553530bb87451 to your computer and use it in GitHub Desktop.
Summarise list of IPs
# Simplest way I know to summarise a list of subnets
import netaddr as ip
ips = [ip.IPNetwork(line.rstrip('\n')) for line in open('ip_prefixes2')]
ip.cidr_merge(ips)
# More info at https://netaddr.readthedocs.io/en/latest/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment