Efficient management of IP address ranges is critical in network engineering, cloud infrastructure, and cybersecurity. CIDR (Classless Inter-Domain Routing) blocks provide a compact way to represent IP address ranges but handling them manually can be cumbersome. Enter the CIDR-Converter, a Go-based utility designed to simplify this process while supporting expanded input formats.
Check out my repo here:
A command-line utility written in Go that processes, validates, and merges IP address ranges in various formats. The tool supports CIDR notation, wildcard notation, and multiple input/output formats.
Ensure you have Go installed on your system, then:
git clone [repository-url] cd [repository-name] go build
The tool supports three input modes:
git clone [repository-url] cd [repository-name] go build
I'm also planning to create a web-app with additional features, to increase functionality and scope of the application!
This project was inspired by Andy Walker's cidr-convert repository.
Handling large lists of CIDRs can be tedious, especially when dealing with overlapping or adjacent ranges. Manually aggregating these ranges is error-prone and time-consuming. This tool automates the process, ensuring optimal aggregation and reducing the risk of mismanagement.
The parseCIDR function ensures input conforms to valid CIDR notation.
Reads CIDRs from CSV and JSON formats using parseCSV and parseJSON functions.
The merged CIDRs are saved to a JSON file for easy consumption by other tools or teams.
Run the tool directly from the terminal, specifying input type:
git clone [repository-url] cd [repository-name] go build
Given the input:
./cidr-processor <span># Enter CIDR blocks interactively, one per line:</span> 192.168.1.0/24 10.0.0.* <span># Press Ctrl+D (Linux/Mac) or Ctrl+Z (Windows) to</span>
The tool outputs a single aggregated block:
# Standard input $ go run main.go Enter CIDR blocks, one per line. Press Ctrl+D (Linux/Mac) or Ctrl+Z (Windows) to end input: 192.168.0.0/24 192.168.1.0/24 # CSV Input $ go run main.go input.csv # JSON Input $ go run main.go input.json
Saved to merged_cidrs.json.
Wildcards like 192.168.. are converted into CIDRs:
192.168.0.0/24 192.168.1.0/24
The function calculates the appropriate prefix length and constructs a CIDR block.
The mergeCIDRs function eliminates redundancy:
[ "192.168.0.0/23" ]
Aggregation follows with:
git clone [repository-url] cd [repository-name] go build
This step combines adjacent ranges into larger blocks.
CSV and JSON input files are parsed with parseCSV and parseJSON, enabling seamless integration with existing workflows:
./cidr-processor <span># Enter CIDR blocks interactively, one per line:</span> 192.168.1.0/24 10.0.0.* <span># Press Ctrl+D (Linux/Mac) or Ctrl+Z (Windows) to</span>
Go's robust standard library, including packages like net, regexp, and encoding/json, makes it an excellent choice for building network-related tools. Its strong concurrency model ensures high performance, even with large datasets.
The Enhanced CIDR Block Calculator simplifies CIDR management with expanded input formats, intelligent merging, and robust file support. Its versatility makes it a valuable tool for network engineers, cloud architects, and cybersecurity professionals. Inspired by Andy Walker's cidr-convert, this tool builds upon foundational ideas to offer a more comprehensive solution. Give it a try and streamline your CIDR workflows today!
The above is the detailed content of Enhanced CIDR Block Calculator with Expanded Input Formats in Go. For more information, please follow other related articles on the PHP Chinese website!