Skip to main content

Networking

Concepts

Future

IPv6

The Office of Management and Budget (OMB) has instructed all Federal agencies to begin moving to Internet Protocol Version 6 (IPv6) starting in 2022.  Completing the transition to an IPv6 infrastructure will require 20% of systems to move to IPv6 by the end of the Fiscal Year (FY) 2023 and 80% by FY 2025.

Subnetting Tools

I do a fair amount with IP ranges, especially on IPv6 and especially with Verizon which tends to change the IPv6 prefix they assign me every time a strong wind blows.

Often I find myself normalizing IPv4 addresses to a /24 network and IPv6 to a /56 CIDR and discovered that the Python 3 ipaddress package does an excellent job of it.

I use the IPv6Interface class to take in a IP address with a CIDR and then convert it to the network with ipaddress.IPv6Interface(f"{ip}/56").network. The script below is a method I use to take a whole list of troublesome hosted server IPs from my log files and add them to my firewall as assigned ranges.

import ipaddress
import sys

def convert_to_cidr(ip_list):
converted_set = set()

for ip in ip_list:
if ':' not in ip:
# IPv4 handling, convert to /24 CIDR
network = ipaddress.IPv4Interface(f"{ip}/24").network
else:
# IPv6 handling, convert to /56 CIDR using IPv6Interface
network = ipaddress.IPv6Interface(f"{ip}/56").network

converted_set.add(str(network))

return converted_set

def main():
ip_list = [line.strip() for line in sys.stdin if line.strip()]
unique_cidrs = convert_to_cidr(ip_list)
print('\n'.join(sorted(unique_cidrs)))

if __name__ == "__main__":
main()