A clean, fast command-line tool written in Go that calculates and displays comprehensive subnet information for CIDR notation inputs. Perfect for network engineers, system administrators, and anyone working with IP subnetting.
- ๐ CIDR Parsing: Parse and validate CIDR notation (e.g., 192.168.1.0/24)
- ๐ Network Information: Display network ID, broadcast address, subnet mask, and wildcard mask
- ๐ Host Information: Show first/last usable IP addresses and total host count
- ๐ Subnet Analysis: Calculate and list all possible subnets for the next prefix level
- ๐ Multiple Output Formats: Support for console text output and HTML file generation
- โก Edge Case Handling: Proper handling of /31 (point-to-point) and /32 (host route) networks
- ๐ Cross-Platform: Works on Linux, macOS, and Windows
- Go 1.19 or later
- Clone the repository:
git clone https://github.com/marc-poljak/simple-cidr-calculator.git
cd simple-cidr-calculator
- Build the binary:
go build -o simple-cidr-calculator
- (Optional) Install globally:
go install
If you have Make installed, you can use the provided Makefile:
# Build for current platform
make build
# Build for all platforms
make build-all
# Clean build artifacts
make clean
# Run tests
make test
simple-cidr-calculator <CIDR>
Usage:
simple-cidr-calculator [OPTIONS] <CIDR>
Arguments:
CIDR Network in CIDR notation (e.g., 192.168.1.0/24)
Options:
-o, --output FILE Save output to specified file
-h, --html Generate HTML formatted output
--help Show help message
simple-cidr-calculator 192.168.1.0/24
Output:
Network Information:
CIDR: 192.168.1.0/24
Network ID: 192.168.1.0
Broadcast: 192.168.1.255
Subnet Mask: 255.255.255.0
Wildcard Mask: 0.0.0.255
Host Information:
First Usable: 192.168.1.1
Last Usable: 192.168.1.254
Total Hosts: 254
Subnet Information:
Possible /25 Subnets: 2
Subnet List:
192.168.1.0/25 (192.168.1.0 - 192.168.1.127)
192.168.1.128/25 (192.168.1.128 - 192.168.1.255)
simple-cidr-calculator -o network-report.txt 172.16.0.0/16
simple-cidr-calculator --html -o network-report.html 10.0.0.0/8
Point-to-Point Link (/31):
simple-cidr-calculator 192.168.1.0/31
Host Route (/32):
simple-cidr-calculator 192.168.1.1/32
The default text output provides a clean, aligned format suitable for terminal viewing and text file storage.
HTML output generates a professional-looking report with:
- Responsive design for mobile and desktop viewing
- CSS styling with gradient headers and clean tables
- Collapsible sections for large subnet lists
- Print-friendly formatting
- Self-contained file with embedded CSS
The tool calculates subnets by adding exactly one bit to the network prefix, creating two equal-sized subnets that together comprise the original network:
- Input: 192.168.1.0/24 โ Output: Two /25 subnets (each with 128 addresses)
- Input: 10.0.0.0/16 โ Output: Two /17 subnets (each with 32,768 addresses)
- Input: 172.16.0.0/20 โ Output: Two /21 subnets (each with 2,048 addresses)
This approach shows the most common subnetting scenario - dividing a network into two equal halves. Each resulting subnet has exactly half the address space of the original network.
- Standard Networks: /8, /16, /24, /28, etc.
- Point-to-Point Links: /31 networks (RFC 3021)
- Host Routes: /32 networks (single host)
- Large Networks: Efficiently handles /8 networks with performance optimizations
The tool provides clear error messages for common issues:
- Invalid CIDR format
- Invalid IP addresses
- Invalid prefix lengths
- File writing permissions
- Flag combination errors
- Optimized for large networks (e.g., /8 networks)
- Efficient memory usage
- Fast startup time
- Subnet listing limited for very large networks to maintain performance
# Run all tests
go test ./...
# Run tests with coverage
go test -cover ./...
# Run integration tests
go test -tags=integration ./...
# Linux
GOOS=linux GOARCH=amd64 go build -o simple-cidr-calculator-linux
# macOS
GOOS=darwin GOARCH=amd64 go build -o simple-cidr-calculator-macos
# Windows
GOOS=windows GOARCH=amd64 go build -o simple-cidr-calculator-windows.exe
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Enhanced and improved with assistance from Kiro AI - an AI-powered development assistant that helped optimize the codebase, improve documentation, and add comprehensive testing.