1
grepcidr 1.3 - Filter IP addresses matching IPv4 CIDR specification
2
Copyright (C) 2004-2005 Jem E. Berkes <jberkes@pc-tools.net>
3
http://www.pc-tools.net/unix/grepcidr/
4
http://www.sysdesign.ca/
9
grepcidr can be used to filter a list of IP addresses against one or more
10
Classless Inter-Domain Routing (CIDR) specifications, or arbitrary networks
11
specified by an address range. As with grep, there are options to invert
12
matching and load patterns from a file. grepcidr is capable of comparing
13
thousands or even millions of IPs to networks with little memory usage and
14
in reasonable computation time.
16
grepcidr has endless uses in network software, including: mail filtering and
17
processing, network security, log analysis, and many custom applications.
19
Many thanks to Dick Wesseling <ftu@fi.uu.nl> who suggested an improved data
20
structure format as well as binary search, to improve grepcidr performance.
23
COMPILING & INSTALLING
24
----------------------
25
Edit Makefile to customize the build. Then,
33
grepcidr [-V] [-c] [-v] PATTERN [FILE]
34
grepcidr [-V] [-c] [-v] [-e PATTERN | -f FILE] [FILE]
36
-V Show software version
37
-c Display count of the matching lines, instead of showing the lines
38
-v Invert the sense of matching, to select non-matching IP addresses
39
-e Specify pattern(s) on command-line
40
-f Obtain CIDR and range pattern(s) from file
42
PATTERN specified on the command line may contain multiple patterns
43
separated by whitespace or commas. For long lists of network patterns,
44
specify a -f FILE to load where each line contains one pattern. Comment
45
lines starting with # are ignored, as are any lines that don't parse.
47
Each pattern, whether on the command line or inside a file, may be:
48
CIDR format a.b.c.d/xx
49
IP range a.b.c.d-e.f.g.h
56
grepcidr -f ournetworks blocklist > abuse.log
57
Find our customers that show up in blocklists
59
grepcidr 127.0.0.0/8 iplog
60
Searches for any localnet IP addresses inside the iplog file
62
grepcidr "192.168.0.1-192.168.10.13" iplog
63
Searches for IPs matching indicated range in the iplog file
65
script | grepcidr -vf whitelist > blacklist
66
Create a blacklist, with whitelisted networks removed (inverse)
68
grepcidr -f list1 list2
69
Cross-reference two lists, outputs IPs common to both lists