From fcf9d6e8268239c8047959c21f564967868e1c1a Mon Sep 17 00:00:00 2001 From: Andrevich <47223721+1andrevich@users.noreply.github.com> Date: Sun, 8 Dec 2024 01:21:45 +0400 Subject: [PATCH 1/2] Update ipsum_bgp.py Replaced BGPView for ip.guide --- src/step 5 ooni list/ipsum_bgp.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/step 5 ooni list/ipsum_bgp.py b/src/step 5 ooni list/ipsum_bgp.py index 5112e8b..560fe7e 100644 --- a/src/step 5 ooni list/ipsum_bgp.py +++ b/src/step 5 ooni list/ipsum_bgp.py @@ -5,6 +5,8 @@ import requests import ipaddress import time import os +import subprocess +import json from collections import defaultdict from idna import encode as idna_encode @@ -100,25 +102,17 @@ def handle_rate_limit(): logging.warning(f'Rate limit hit. Waiting for {wait_time} seconds.') time.sleep(wait_time) -# Function to get CIDRs for a domain from ASN using GeoLite2 +# Function to get CIDRs for a domain from ASN using ip.guide def get_cidr_for_asn(asn): try: - url = f'https://api.bgpview.io/asn/{asn}/prefixes' - response = requests.get(url) - - if response.status_code == 200: - data = response.json() - return [prefix['prefix'] for prefix in data['data']['ipv4_prefixes']] - - elif response.status_code == 429: - handle_rate_limit() - return get_cidr_for_asn(asn) # Retry after waiting - - elif response.status_code == 403: - logging.error(f'Access forbidden for ASN {asn}, skipping.') + command = f'curl -sL https://ip.guide/as{asn}' + result = subprocess.run(command, shell=True, capture_output=True, text=True) + if result.returncode == 0: + data = json.loads(result.stdout) + return data.get('routes', {}).get('v4', []) + else: + logging.error(f'Error executing curl command: {result.stderr}') return [] - - return [] except Exception as e: logging.error(f'Error retrieving CIDRs for ASN {asn}: {e}') return [] From 29623380d6115983a2eb6fd35225c743aef45a67 Mon Sep 17 00:00:00 2001 From: Andrevich <47223721+1andrevich@users.noreply.github.com> Date: Sun, 8 Dec 2024 01:32:59 +0400 Subject: [PATCH 2/2] Update build.yml --- .github/workflows/build.yml | 43 +++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 82c68b4..1848b19 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,7 +18,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: '3.9' # Use the appropriate Python version + python-version: '3.9' - name: Install dependencies run: | @@ -27,32 +27,67 @@ jobs: - name: Prepare directories for build run: | - if [ ! -d "sum/input" ]; then mkdir -p sum/input; fi - if [ ! -d "sum/output" ]; then mkdir -p sum/output; fi + mkdir -p sum/input + mkdir -p sum/output - name: Run OONI Parser (ooni_domains.lst) run: python "src/step 5 ooni list/ooni_list.py" + - name: Verify OONI Parser Output + run: | + echo "Files in sum/input after OONI Parser:" + ls -la sum/input + ##Community.lst and Domains.lst are already in the sum/input folder - name: Run Domain Sum Up script (domains_all.lst) run: python "src/step 5 ooni list/domain_sum.py" + - name: Verify Domain Sum Output + run: | + echo "Files in sum/output after Domain Sum:" + ls -la sum/output + - name: Run OONI Resolver script (ooni_ips.lst) run: python "src/step 5 ooni list/resolver_ooni.py" - + + - name: Verify OONI Resolver Output + run: | + echo "Files in sum/input after OONI Resolver:" + ls -la sum/input + - name: Run Community Resolver script (ip_community.lst) run: python "src/step 5 ooni list/resolver_community.py" + - name: Verify Community Resolver Output + run: | + echo "Files in sum/input after Community Resolver:" + ls -la sum/input + - name: Run IP Sum (Temp) script (ips_all.lst) run: python "src/step 5 ooni list/ip_4files_sum.py" + - name: Verify IP Sum Temp Output + run: | + echo "Files in sum/input after IP Sum Temp:" + ls -la sum/input + - name: Run IP Sum + ASN (Final) script (ipsum.lst) run: python "src/step 5 ooni list/ipsum_bgp.py" + - name: Verify Ipsum Output + run: | + echo "Files in sum/output after Ipsum Sum:" + ls -la sum/output + - name: Run Bird2 Converter script run: python "src/step 5 ooni list/bird2_converter.py" + - name: Verify Bird2 Output + run: | + echo "Files in sum/output after Bird2 Converter:" + ls -la sum/output + - name: Convert files to LF (Unix format) run: | sudo apt-get update && sudo apt-get install -y dos2unix