### Compile and Install grepcidr Source: https://context7.com/jrlevine/grepcidr3/llms.txt Build the grepcidr utility from source using make. Install it to standard locations or a custom prefix. The test suite can be run to verify the build. ```bash # Compile make # Install to /usr/local/bin and /usr/local/man/man1 make install # Optional: install to a custom prefix make INSTALLDIR=/opt/grepcidr install # Run the test suite (requires a compiled binary) make test # Output: # Running test suite... # Running tests/test_o_option.sh... # All tests passed! # All test suites passed! # Debug build (prints hex representation of parsed IPs and matches to stderr) make CFLAGS="-g -Wall -pedantic -DDEBUG=1" ``` -------------------------------- ### Batch Processing Example Source: https://github.com/jrlevine/grepcidr3/blob/main/tests/TEST_O_OPTION.md Process multiple IP addresses from a file against a set of patterns using the -o option and redirect the classified patterns to an output file. ```bash cat ips.txt | ./grepcidr -o -f patterns.txt > classifications.txt ``` -------------------------------- ### Narrowest Match Example Source: https://github.com/jrlevine/grepcidr3/blob/main/tests/TEST_O_OPTION.md Demonstrates how the -o option selects the narrowest CIDR pattern when an IP matches multiple overlapping ranges. Ensure patterns.txt contains the specified CIDR ranges. ```bash cat patterns.txt 192.168.0.0/16 192.168.1.0/24 192.168.1.128/25 echo "192.168.1.200" | ./grepcidr -o -f patterns.txt # Output: 192.168.1.128/25 ``` -------------------------------- ### Show grepcidr version Source: https://context7.com/jrlevine/grepcidr3/llms.txt Display the version of the grepcidr tool using the -V flag. This is standard practice for verifying the installed version or for troubleshooting. ```bash grepcidr -V ``` -------------------------------- ### Anchor matches to the start of a line Source: https://context7.com/jrlevine/grepcidr3/llms.txt Use the -a flag to ensure that matched IP addresses appear at the beginning of a line, optionally preceded by whitespace. This is helpful for parsing structured log files where the IP is the first field. ```bash grepcidr -a "192.168.0.0/16" /var/log/auth.log ``` ```bash # Combine with -v to find lines NOT starting with a private IP grepcidr -av "10.0.0.0/8,192.168.0.0/16" iplist.txt ``` -------------------------------- ### AWS IP Range Classification Example Source: https://github.com/jrlevine/grepcidr3/blob/main/tests/TEST_O_OPTION.md Classify a specific IP address against a set of AWS IP ranges using the -o option. The output will be the most specific matching AWS CIDR range. ```bash # Create a pattern file with AWS IP ranges cat > aws_ranges.txt < network.txt < blocklist.txt ``` -------------------------------- ### Create New Test Script Source: https://github.com/jrlevine/grepcidr3/blob/main/tests/README.md Template for creating a new test script for a specific grepcidr option. Follow this pattern for creating executable test files. ```bash make test ``` -------------------------------- ### Run Comprehensive Test Suite Source: https://github.com/jrlevine/grepcidr3/blob/main/tests/TEST_O_OPTION.md Execute the automated test suite to cover all aspects of the -o option functionality. ```bash ./test_o_option.sh ``` -------------------------------- ### Make Test Script Executable Source: https://github.com/jrlevine/grepcidr3/blob/main/tests/README.md Set execute permissions for a newly created test script. This is a required step before the script can be run. ```bash chmod +x test_