Skip to content

Instantly share code, notes, and snippets.

@lanbugs
Created May 12, 2023 18:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Subnet merge show right subnets which are not in left subnets
import sys
from netaddr import IPNetwork
from pprint import pprint
# right must be in left
def main(left_side, right_side):
with open(right_side, "r") as f:
raw_right = f.readlines()
with open(left_side, "r") as f:
raw_left = f.readlines()
right = []
left = []
not_found = []
# clean lines
for line in raw_right:
right.append(line.strip())
for line in raw_left:
left.append(line.strip())
try:
for r in right:
FOUND = False
for l in left:
if IPNetwork(r) in IPNetwork(l):
FOUND = True
print(f"Found {r} in {l}")
if FOUND is False:
not_found.append(r)
except Exception as e:
print(e)
pprint(not_found)
if __name__ == "__main__":
main(sys.argv[1], sys.argv[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment