-1

I have 2 files that contain subnets in cidr format (212.234.96.0/24, 80.10.0.0/24, ...) liny by line. I will like you to create a python script that will tell me overlapping subnets. Input are file1 (list of subnets, more than 4000) and file2 (list that I want to check with file1). I want the output in file3 with the file2 subnets without overlapping.

For the other hand, I did this work in a shell script but the processing time is too long (for the +4000 subnets processing). Some people recommended that I should do this work in python. The problem is I'm new in python.

Thank you.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • Pure code-writing requests are off-topic on Stack Overflow -- we expect questions here to relate to *specific* programming problems -- but we will happily help you write it yourself! Tell us [what you've tried](https://stackoverflow.com/help/how-to-ask), and where you are stuck. This will also help us answer your question better. – Błażej Michalik Apr 13 '18 at 08:12

1 Answers1

1

Rough outline:

  1. read file1 into array subnet with subnet address, netmask, convert both to unsigned int32
  2. read entry from file2, convert to unsigned int32
  3. for each subnetelement, if (entry.uint32 & subnet.netmask.uint32) == (subnet.address.uint32 & subnet.netmask.uint32) then entry is inside subnet
  4. if entry is not in any subnet, write entry to file3

You can do this in pretty much any language you like.

Zac67
  • 2,761
  • 1
  • 10
  • 21