Skip to content

Instantly share code, notes, and snippets.

@lanbugs
Created May 12, 2023 18:00
Show Gist options
  • Save lanbugs/e212abb2415e7637c178362a1bdaa6f8 to your computer and use it in GitHub Desktop.
Save lanbugs/e212abb2415e7637c178362a1bdaa6f8 to your computer and use it in GitHub Desktop.
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