Quote:
Originally Posted by Noodle Wazlib
Doing a project where I have, say, a mix of 500 IP address and IP ranges. I have a second, smaller set of IPs and ranges that need to be removed from the original list.
What would be the way to handle this?
I was thinking maybe use python and put both lists into files. Read each file into a variable/python list, where a single IP is a single entry, and a range is itself a list with the starting and ending IP as the two list items.
From there, iterate over the 2nd list and check if the items are equal or if the item in the 2nd list is within the range of the first. If so, I'm not entirely sure how to remove the item or alter it.
Like, if an included range is 10.0.0.1 through 10.0.0.10, and one to be excluded is 10.0.0.5, I need the first list to then contain [10.0.0.1, 10.0.0.4] and also [10.0.0.6, 10.0.0.10]
Does that make sense? How would I approach that second part? And is there a good python module that makes working with and comparing IPs easy? (Or ruby or bash)
Edit
Looks like python 3 has the ipaddress module which at least lets me easily compare addresses, so that's a start.
I don't know how fast it is but array slicing can maybe help with splitting lists:
http://pythoncentral.io/how-to-slice...les-in-python/
Also search for "most efficietnt algsorithm for finding an integer in a range". It help you with determining if ips belong in a range.
From what I remember it goes something like this:
1. Create and sort separate arrays for your starting points and ending points
2. Use a merge sort type of method to walk through the 2 arrays and determine if some value is still active in some main list of objects.
It was used to solve a separate problem (like counting integers still active in a larger range) but it might help with you determining if a value is within a set of ips and you can use the logic to potentially do what you need.
Also I feel like that since ips can be expressed easily as binary numbers there could be some binary manipulation trickery that I can't think of at the moment that would do the job but I may be over reaching there haha.
Sent from my SM-G900R4 using Tapatalk