A CLI wrapper for the cidr-tools package, specifically wrapping the containsCidr method to check if an IP address is contained within CIDR ranges.
npm install -g cidr-clinpm install cidr-clinpx cidr-cli contains <cidr-list> <ip>cidr-cli contains <cidr-list> <ip><cidr-list>: Comma-separated list of CIDR ranges (e.g.,192.168.1.0/24,10.0.0.0/8)<ip>: IP address to check (IPv4 or IPv6)
# Single CIDR range
cidr-cli contains 192.168.1.0/24 192.168.1.100
# Output: true
# Multiple CIDR ranges
cidr-cli contains 10.0.0.0/8,172.16.0.0/12 10.1.2.3
# Output: true
# User's example
cidr-cli contains 1.0.0.0/24,2.0.0.0/24 1.0.0.1
# Output: true
# IPv6 support
cidr-cli contains 2001:db8::/32 2001:db8:0:0:1::1
# Output: true
# IP not in range
cidr-cli contains 1.0.0.0/24,2.0.0.0/24 3.0.0.1
# Output: false
# Help
cidr-cli --help0: IP is contained in one of the CIDR ranges1: IP is not contained in any of the CIDR ranges2: Error occurred (invalid arguments, invalid CIDR format, invalid IP, etc.)
#!/bin/bash
if cidr-cli contains 192.168.0.0/16 $USER_IP; then
echo "User is on local network"
else
echo "User is on external network"
fi- name: Check if IP is in allowed range
run: |
if ! cidr-cli contains 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 ${{ env.SERVER_IP }}; then
echo "Server IP not in allowed private ranges"
exit 1
fi# Check if suspicious IP is in known bad ranges
if cidr-cli contains 1.2.3.0/24,5.6.7.0/24 $SUSPICIOUS_IP; then
echo "IP is in known malicious range - blocking"
# Add blocking logic here
fi- Node.js >= 14.0.0
- npm >= 6.0.0
git clone https://github.com/n-ae/cidr-cli.git
cd cidr-cli
npm install# Run tests (Jest with ES modules)
npm test
# Run tests with coverage (c8 + Jest)
npm run test:coverage
# Run tests in watch mode
npm run test:watch# Check for linting issues
npm run lint
# Fix linting issues automatically
npm run lint:fix# Generate JSDoc documentation
npm run docscidr-cli/
βββ index.js # Main CLI implementation (ES modules)
βββ index.test.js # Jest test suite (13 comprehensive tests)
βββ package.json # Package configuration
βββ package-lock.json # Lockfile v2 for CI compatibility
βββ README.md # This file
βββ LICENSE # MIT license
βββ CHANGELOG.md # Version history
βββ PUBLISHING.md # Publishing guide
βββ WARP.md # Claude/Warp AI development guide
βββ eslint.config.js # ESLint flat configuration (neostandard)
βββ jest.config.js # Jest configuration (ES modules)
βββ .c8rc.json # c8 coverage configuration
βββ jsdoc.conf.json # JSDoc configuration
βββ .npmignore # npm publish exclusions
βββ .gitignore # Git exclusions
βββ .github/
β βββ workflows/ # GitHub Actions CI/CD (Node 14-21 matrix)
βββ docs/ # Generated JSDoc documentation
βββ coverage/ # c8 coverage reports (HTML + LCOV)
βββ tests/ # Legacy test files (kept for reference)
This package uses automated publishing via GitHub Actions:
- On Push/PR: Runs full test suite across Node.js 14.x, 16.x, 18.x, 20.x, 21.x
- On Tag: Automatically publishes to npm and creates GitHub release
npm version patch|minor|major
git push origin main --tagsThe project maintains 100% test coverage using c8:
- 13 test cases covering all functionality and edge cases
- Integration tests: End-to-end CLI execution via
child_process.spawn() - Coverage tool: c8 (Node.js native coverage) instead of Jest built-in
- Coverage threshold: 80% minimum, currently achieving 100%
- Reports: Text, LCOV (for Codecov), and HTML formats
Test categories:
- β CIDR containment checks (IPv4/IPv6)
- β Multiple CIDR range support
- β Help and usage information
- β Error handling (invalid CIDR, invalid IP, malformed arguments)
- β Exit code validation
- β Whitespace handling in CIDR lists
- β Process-level coverage tracking
- cidr-tools ^13.0.1 - Core CIDR functionality
- jest ^30.5.0 - Testing framework
- c8 ^12.0.0 - Native Node.js code coverage
- eslint ^9.39.5 - Code linting (flat config)
- neostandard ^0.13.0 - Standard style guide for flat config
- jsdoc ^4.0.5 - Documentation generation
- ES Modules: Modern JavaScript module system
- Node.js 14+: Minimum Node.js version support
- CI/CD: GitHub Actions with Node.js 14.x-21.x matrix
- Coverage: 100% code coverage with c8
- Lockfile v2: Enhanced CI compatibility
π License
MIT Β© nae
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -am 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
If you find a bug, please file an issue on GitHub Issues.
- Add support for excluding CIDR ranges
- Add JSON output format option
- Add batch processing from file input
- Add verbose mode with detailed matching information
- Add support for hostname resolution
Made with β€οΈ for network administrators and DevOps engineers