Skip to content

Instantly share code, notes, and snippets.

@Gunni
Last active August 25, 2019 07:14
Show Gist options
  • Save Gunni/112e0aad9534ca6eb078f1cbdc8341d2 to your computer and use it in GitHub Desktop.
Save Gunni/112e0aad9534ca6eb078f1cbdc8341d2 to your computer and use it in GitHub Desktop.
Just to show how huge IPv6 is
from collections import defaultdict
import requests
import csv
import ipaddress
import datetime
print(f'# {datetime.datetime.utcnow()}')
assignmentsFile = requests.get('https://www.iana.org/assignments/ipv6-unicast-address-assignments/ipv6-unicast-address-assignments.csv')
assignmentsFile.raise_for_status()
globalNetwork = ipaddress.ip_network('2000::/3')
totals = defaultdict(int)
for line in csv.DictReader(assignmentsFile.text.split('\n')):
prefixed = ipaddress.ip_network(line['Prefix'])
if not globalNetwork.supernet_of(prefixed):
continue
totals[line['Status']] += prefixed.num_addresses
allv6 = ipaddress.ip_network('::/0')
for status, n in totals.items():
perc = (n / globalNetwork.num_addresses) * 100
percAll = (n / allv6.num_addresses) * 100
print(f'{perc:.5}% of {globalNetwork} has been {status} (which is only {percAll:.5} of ::/0!)')
# 2019-08-25 07:13:39.908520
1.1948% of 2000::/3 has been ALLOCATED (which is only 0.14935 of ::/0!)
59.387% of 2000::/3 has been RESERVED (which is only 7.4234 of ::/0!)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment