Prefix Fetcher is a Go-based tool for fetching country-specific IP prefixes from BGP data. Dynamically fetches ASN lists from Regional Internet Registry (RIR) delegated files and filters BGP prefixes accordingly.
- Dynamic ASN Fetching: Automatically downloads the latest ASN allocations from RIR delegated files
- Iran (IR): Uses RIPE NCC delegated data
- China (CN): Uses APNIC delegated data
- Russia (RU): Uses RIPE NCC delegated data
- Comprehensive Coverage: Fetches from all RIRs for complete ASN discovery
- BGP Data: Fetches IP prefixes from bgp.tools
- IPv4 /24 Blocks: Converts IPv4 prefixes to /24 blocks for efficient processing
- IPv6 Preservation: Keeps IPv6 prefixes in their original format
- Clean & Simple: No caching, fresh data on every run
- Automatic retry logic with exponential backoff
- Duplicate removal: Automatically deduplicates ASNs found across multiple RIRs
- Go (>=1.24)
-
Clone the repository:
git clone https://github.com/compassvpn/prefix-fetcher.git cd prefix-fetcher
-
Build the application:
go build -o prefix-fetcher
./prefix-fetcher [OPTIONS]
Option | Description |
---|---|
--fetch-ir |
Fetch Iranian IP prefixes |
--fetch-cn |
Fetch Chinese IP prefixes |
--fetch-ru |
Fetch Russian IP prefixes |
-h, --help |
Show help information |
-
Fetch Iranian IP prefixes:
./prefix-fetcher --fetch-ir
-
Fetch Chinese IP prefixes:
./prefix-fetcher --fetch-cn
-
Fetch Russian IP prefixes:
./prefix-fetcher --fetch-ru
-
Fetch multiple countries:
./prefix-fetcher --fetch-ir --fetch-cn --fetch-ru
-
Show help:
./prefix-fetcher --help
The tool generates country-specific prefix files:
Iranian prefixes:
ir_prefixes_v4.txt
- IPv4 prefixes as /24 blocksir_prefixes_v6.txt
- IPv6 prefixes
Chinese prefixes:
cn_prefixes_v4.txt
- IPv4 prefixes as /24 blockscn_prefixes_v6.txt
- IPv6 prefixes
Russian prefixes:
ru_prefixes_v4.txt
- IPv4 prefixes as /24 blocksru_prefixes_v6.txt
- IPv6 prefixes
- Fetches ASN Lists: Downloads the latest ASN allocations from all RIRs for comprehensive coverage:
- Iran: Primary coverage from RIPE NCC, with additional checks across all RIRs
- China: Primary coverage from APNIC, with additional checks across all RIRs
- Russia: Primary coverage from RIPE NCC, with additional checks across all RIRs
- Downloads BGP Data: Fetches the complete BGP routing table from bgp.tools
- Filters by ASN: Keeps only prefixes from the dynamically fetched ASN lists
- Processes IPv4: Converts IPv4 prefixes to /24 blocks for consistency
- Sorts and Saves: Outputs clean, sorted prefix lists to text files
- RIR Delegated Files:
- BGP Data: bgp.tools
This project is licensed under the MIT License.
Contributions are welcome! Feel free to fork the repository and submit a pull request.