mirror of
https://github.com/lord-alfred/ipranges.git
synced 2025-12-19 03:37:47 +00:00
add ip merge script
This commit is contained in:
23
.github/workflows/update.yml
vendored
23
.github/workflows/update.yml
vendored
@@ -14,6 +14,29 @@ jobs:
|
||||
- name: Download Google IPs
|
||||
run: bash google/downloader.sh
|
||||
|
||||
- name: Set up Python 3.7
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: '3.7'
|
||||
|
||||
- name: Cache pip
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.cache/pip
|
||||
key: ${{ runner.os }}-pip-${{ hashFiles('utils/requirements.txt') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pip-
|
||||
${{ runner.os }}-
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
pip install -r utils/requirements.txt
|
||||
|
||||
- name: Merge IPv4 ranges
|
||||
run: |
|
||||
set -euo pipefail
|
||||
python utils/merge.py --source=google/ipv4.txt | sort -h > google/ipv4_merged.txt
|
||||
|
||||
- name: Commit files
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
23
utils/merge.py
Normal file
23
utils/merge.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import argparse
|
||||
|
||||
import netaddr
|
||||
|
||||
|
||||
def read(fh):
|
||||
for line in fh:
|
||||
yield line.rstrip()
|
||||
|
||||
fh.close()
|
||||
|
||||
|
||||
def merge(fh):
|
||||
for addr in netaddr.cidr_merge(read(fh)):
|
||||
print(addr)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='Merge IP addresses into the smallest possible list of CIDRs.')
|
||||
parser.add_argument('--source', nargs='?', type=argparse.FileType('r'), required=True, help='Source file path')
|
||||
args = parser.parse_args()
|
||||
|
||||
merge(args.source)
|
||||
1
utils/requirements.txt
Normal file
1
utils/requirements.txt
Normal file
@@ -0,0 +1 @@
|
||||
netaddr==0.8.0
|
||||
Reference in New Issue
Block a user