Skip to content

Instantly share code, notes, and snippets.

@raspi
Last active June 23, 2020 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raspi/c61b6e8a8163bd840acdf8dfbdc76bee to your computer and use it in GitHub Desktop.
Save raspi/c61b6e8a8163bd840acdf8dfbdc76bee to your computer and use it in GitHub Desktop.
IP Address range to CIDR
#!/usr/bin/env python3
# IP address range to CIDR
import sys
import ipaddress
if (len(sys.argv) - 1) != 2:
print("Usage: ")
print(f" {sys.argv[0]} <ip address> <ip address>")
print("Example: ")
print(f" {sys.argv[0]} 192.168.0.0 192.168.0.255")
sys.exit(0)
ip1 = ipaddress.ip_address(sys.argv[1])
ip2 = ipaddress.ip_address(sys.argv[2])
for i in ipaddress.summarize_address_range(ip1, ip2):
print(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment