- Go 34.6%
- Perl 32.8%
- Shell 32.2%
- Makefile 0.4%
|
|
||
|---|---|---|
| .forgejo/workflows | ||
| ai | ||
| packaging | ||
| perl | ||
| .gitignore | ||
| .gogogo.conf | ||
| CLAUDE.md | ||
| go.mod | ||
| go.sum | ||
| ip.go | ||
| ip_test.go | ||
| LICENSE.txt | ||
| main.go | ||
| parse.go | ||
| parse_test.go | ||
| README.md | ||
grip
Search and manage IP address list files.
grip finds files that contain a given IP address — either as a literal
host entry or because it falls inside a listed CIDR block. A companion
remove subcommand deletes the address from matching files in-place,
automatically splitting any CIDR that would otherwise swallow it.
Both IPv4 and IPv6 are supported throughout.
File format
One or more entries per line. Each entry is either:
- a host address:
192.168.0.1,::1 - a CIDR block:
192.168.0.0/24,2001:db8::/32
Multiple entries on the same line may be separated by any non-IP characters (commas, semicolons, spaces, tabs, etc.):
# production edge nodes
203.0.113.10
203.0.113.11
# lab range
198.51.100.0/24
# mixed — comma-separated
10.0.0.1, 10.0.0.2, 192.168.0.0/24
Comments (leading #) and blank lines are preserved unchanged.
Installation
go install go.schlittermann.de/heiko/grip@latest
Or build from source:
git clone git@git.schlittermann.de:heiko/grip.git
cd grip
go build -o grip .
Usage
grip [search] [-r] <ip> <path>...
grip remove [-r] [-backup[=suffix]] <ip> <path>...
search is the default subcommand and can be omitted.
Options
| Flag | Applies to | Description |
|---|---|---|
-r |
both | Recurse into directories |
-backup[=suffix] |
remove |
Back up each modified file before changing it; suffix is appended to the filename (default .bak) |
Search
Prints every matching line in grep style (file:line: content):
$ grip 198.51.100.5 /etc/ipsets/
/etc/ipsets/lab.txt:4: 198.51.100.0/24
Exit status is non-zero when the address is not found in any file.
Remove
Removes the address from every file that contains it. If the address is covered by a CIDR, the CIDR is replaced by the minimal set of sub-CIDRs that covers the original range minus the single address:
$ grip remove 198.51.100.5 /etc/ipsets/lab.txt
/etc/ipsets/lab.txt:4: 198.51.100.0/24 -> [198.51.100.0/29, 198.51.100.4/32, 198.51.100.6/31, ...]
With -backup, the original file is preserved before modification:
# keeps lab.txt.bak
grip remove -backup 198.51.100.5 /etc/ipsets/lab.txt
# keeps lab.txt.orig
grip remove -backup=.orig 198.51.100.5 /etc/ipsets/lab.txt
Recursive search across a directory tree
grip -r 10.0.0.1 /etc/ipsets/
Running the tests
go test ./...
Repository layout
. Go implementation (this README, go.mod, *.go)
perl/ Perl implementation — see perl/README.md
perl/t/ Perl test suite (run with: prove perl/t/)
Versioning
Both implementations share a single version tag vX.Y.Z. They are always
released together and kept in sync.