A Python tool to scrape ASN (Autonomous System Number), IPv4, and IPv6 allocation data by country code from RIR delegation statistics.
- π Fetch network data for any country using ISO 3166-1 alpha-2 codes
- π Support for ASN, IPv4, and IPv6 data types
- β‘ Multi-threaded fetching for improved performance
- π Clean data output in CSV and text formats
- π¨ Rich console output with progress tracking
- π³ Docker support for containerized execution
Data source: RIR Delegations & RIPE NCC Allocations
# Clone the repository
git clone https://github.com/hatamiarash7/ASN-By-Country.git
cd ASN-By-Country
# Create virtual environment and install all dependencies
make depspip install -r requirements.txtdocker build -t asn-by-country .python main.py <country_code_1> <country_code_2> ... [options]
# Or using the module
python -m src.cli <country_code_1> <country_code_2> ... [options]-
-d, --data-type <type>: Specify which type of data to fetch. The options are:asn: Retrieve only AS numbers (default).ipv4: Retrieve only IPv4 addresses.ipv6: Retrieve only IPv6 addresses.all: Retrieve AS numbers, IPv4 addresses, and IPv6 addresses.
-
-w, --max-workers <N>: Maximum concurrent workers (default: 5) -
-q, --quiet: Suppress progress output -
-v, --version: Show version
# Fetch ASN data for multiple countries
python main.py IR US FR
# Fetch only ASN data
python main.py IR --data-type asn
# Fetch all data types
python main.py IR US --data-type all
# Using quiet mode with more workers
python main.py IR US DE --quiet --max-workers 10# Create virtual environment and install dependencies
make deps
# Run the program
make run ARGS="US"
make run ARGS="IR US DE --data-type all"
# Run linters and type checker
make check
# Run tests with coverage
make test-cov
# Clean outputs
make clean
# Show all available targets
make helpdocker run --rm -v /results:/app/output_data hatamiarash7/asn-by-country:latest <country_code_1> <country_code_2> ... [options]Using makefile:
make docker-run ARGS="IR"
make docker-run ARGS="US DE"Build docker image only:
make docker-buildThe output will be generated in the output_data directory:
| File Name | Description |
|---|---|
{Country}_asn_list.csv |
Contains a list of ASN delegations for specified country. |
{Country}_ipv4_list.csv |
Contains IPv4-specific ASN delegations for specified country. |
{Country}_ipv6_list.csv |
Contains IPv6-specific ASN delegations for specified country. |
asn_ranges.txt |
Contains a list of all ASN ranges across countries. |
ipv4_ranges.txt |
Contains a list of all IPv4 ranges. |
ipv6_ranges.txt |
Contains a list of all IPv6 ranges. |
ASN-By-Country/
βββ src/ # Source code
β βββ cli.py # Command-line interface
β βββ config.py # Configuration constants
β βββ models.py # Data models
β βββ scraper.py # Web scraping logic
β βββ storage.py # File storage operations
βββ tests/ # Unit tests
βββ Dockerfile
βββ Makefile
βββ pyproject.toml # Project configuration
βββ requirements.txt # Production dependencies
βββ requirements-dev.txt # Development dependencies
| Target | Description |
|---|---|
make help |
Show all available targets |
make deps |
Install all dependencies |
make run ARGS="..." |
Run the application |
make lint |
Run all linters |
make format |
Format code |
make type-check |
Run type checking |
make check |
Run all code quality checks |
make test |
Run tests |
make test-cov |
Run tests with coverage |
make test-junit |
Run tests with JUnit report |
make docker-build |
Build Docker image |
make docker-run ARGS="..." |
Run in Docker |
make clean-all |
Remove all generated files |
Don't be shy and reach out to us if you want to contribute π
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request
Each project may have many problems. Contributing to the better development of this project by reporting them. π