Skip to content

Commit

Permalink
Sort largest IP range to smallest (#2)
Browse files Browse the repository at this point in the history
* Try sorting largest IP range to smallest

* Update README.md
  • Loading branch information
BelleNottelling authored Dec 8, 2023
1 parent 0b7ab1c commit 61ef2e1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The order of processing is as follows:
1. Basic de-duplication by removing duplicate entries of the same CIDR.
- A warning will be generated if a duplicate does not contain the same data as it's original.
- Only the first instance of a CIDR will be retained in the final data source.
2. The de-duplicated list is then sorted.
2. The de-duplicated list is then sorted in decending order by the quantity of IP addresses in each CIDR
3. Any CIDRs which are private networks are discarded.
4. Any 3-letter country codes are converted to 2 letter country codes.
5. Next all CIDRs are looped through and compared against previous CIDRs to identify any overlaps / subnets.
Expand Down
4 changes: 2 additions & 2 deletions scripts/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def process(json_file):
# Quickly handle identical CIDR entries.
ip_data_list = deduplicate(ip_data_list)

# Sort the list based on the IP range
ip_data_list.sort(key=lambda entry: ipaddress.ip_network(entry["ip_range"], strict=False))
# Sort the list based on the number of IP addresses in descending order
ip_data_list.sort(key=lambda entry: ipaddress.ip_network(entry["ip_range"], strict=False).num_addresses, reverse=True)

unique_ranges = set()
result = []
Expand Down

0 comments on commit 61ef2e1

Please sign in to comment.