This Go program extracts IP address ranges for a specific country from the IP2LOCATION-LITE-DB1 database and writes individual IPs to a text file.
Supports both IPv4 and IPv6 via command-line flags.
- Parses CSV database from IP2Location (Lite version).
- Supports IPv4 and IPv6 formats.
- Filters IP ranges by 2-letter country code.
- Skips overly large ranges (>10 million IPs).
- Logs all skipped/invalid ranges.
- High performance via Go routines and buffering.
- Go 1.2+
- IP2Location CSV files:
Place the .CSV files in a ./db/ folder.
go run main.go <COUNTRY_CODE> [--v4 | --v6]<COUNTRY_CODE>: Two-letter ISO 3166-1 alpha-2 country code (e.g.US,UA,DE).--v4: Process IPv4 data fromIP2LOCATION-LITE-DB1.CSV.--v6: Process IPv6 data fromIP2LOCATION-LITE-DB1.IPV6.CSV.
❗ You must specify either
--v4or--v6, not both.
- Output file:
UA.txtfor IPv4UA_ipv6.txtfor IPv6
- Log file:
skipped_UA.logfor skipped or invalid ranges
go run main.go UA --v4go run main.go DE --v6- Large IP ranges (>10 million addresses) are automatically skipped and logged.
- The program uses goroutines and buffered channels to speed up processing.
This project is provided as-is for educational and utility purposes.
IP data © IP2Location LITE under Creative Commons Attribution-ShareAlike 4.0.