Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jmoney/cidr-encoder
CLI for time efficiently encoding cidr blocks to find if an IP exists in a range
https://github.com/jmoney/cidr-encoder
github-site homebrew-formula license-management mkdocs
Last synced: 16 days ago
JSON representation
CLI for time efficiently encoding cidr blocks to find if an IP exists in a range
- Host: GitHub
- URL: https://github.com/jmoney/cidr-encoder
- Owner: jmoney
- License: apache-2.0
- Created: 2024-06-07T20:47:57.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-06-13T02:19:34.000Z (5 months ago)
- Last Synced: 2024-10-16T13:07:24.394Z (about 1 month ago)
- Topics: github-site, homebrew-formula, license-management, mkdocs
- Language: Go
- Homepage: https://www.jmoney.dev/cidr-encoder
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Cidr Encoder
Converts a list of CIDRs to an encoded file for time efficient lookups on is a given IP address in any of the CIDR blocks. Each CIDR block is on its own line in the input file. The output file is a binary file that can be read by the `cidr-encoder` program for searching. The lookup time is `O(1)` for any IP address. However, to achieve this the output file can easily be several GBs if there are a wide range of CIDR blocks across the IPv4 addresses space.
The calculation for how big a file would take is effectively the largest IP - the smallest IP. As the algorithm uses file offsets to determine if an IP is in a list of CIDR blocks, the largest IP is the largest offset in the file. We use the smallest IP to normalize everything to first offset of a file. This is done to reduce the size of the file so the difference between the two is the size of the file.
## Usage
```bash
$ cidr-encoder -h
Usage of cidr-encoder:
-calc
Calculate the size of the encoded file. Reads from STDIN.
-encode
Encode the CIDRs. Reads from STDIN.
-name string
The file base name to use as the ACL file name(e.g test.acl name is test).
-search string
Search for a IP in the CIDRs.
````-calc`, `encode`, and `search` are all mutually exclusive but the priority in the event that all are specified are `calc` then `encode` then `search`.