debian/0000775000000000000000000000000012237751201007170 5ustar debian/watch0000664000000000000000000000010611630771747010233 0ustar version=3 http://www.pc-tools.net/files/unix/ grepcidr-(.*)\.tar\.gz debian/grepcidr.10000664000000000000000000000447311630762111011057 0ustar .TH "GREPCIDR" "1" .SH "NAME" grepcidr \(em Filter IP addresses matching IPv4 CIDR/network specification .SH "SYNOPSIS" .PP \fBgrepcidr\fR [\fB-V\fP] [\fB-c\fP] [\fB-v\fP] [\fB-e \fIpattern\fR\fP | \fB-f \fIfile\fR\fP] .SH "DESCRIPTION" .PP This manual page documents briefly the \fBgrepcidr\fR command. .PP This manual page was written for the \fBDebian\fP distribution because the original program does not have a manual page. .PP \fBgrepcidr\fR can be used to filter a list of IP addresses against one or more Classless Inter-Domain Routing (CIDR) specifications, or arbitrary networks specified by an address range. As with grep, there are options to invert matching and load patterns from a file. grepcidr is capable of comparing thousands or even millions of IPs to networks with little memory usage and in reasonable computation time. .SH "OPTIONS" .IP "\fB-V\fP" 10 Show software version .IP "\fB-c\fP" 10 Display count of the matching lines, instead of showing the lines .IP "\fB-v\fP" 10 Invert the sense of matching, to select non-matching IP addresses .IP "\fB-e\fP" 10 Specify pattern(s) on command-line .IP "\fB-f\fP" 10 Obtain CIDR and range pattern(s) from file .SH "EXAMPLES" .PP \fI\fBgrepcidr\fP \-f ournetworks blocklist > abuse.log\fP .PP Find our customers that show up in blocklists .PP \fI\fBgrepcidr\fP 127.0.0.0/8 iplog\fP .PP Searches for any localnet IP addresses inside the iplog file .PP \fI\fBgrepcidr\fP "192.168.0.1-192.168.10.13" iplog\fP .PP Searches for IPs matching indicated range in the iplog file .PP \fI\fBscript\fP | \fBgrepcidr\fP \-vf whitelist > blacklist\fP .PP Create a blacklist, with whitelisted networks removed (inverse) .PP \fI\fBgrepcidr\fP \-f list1 list2\fP .PP Cross-reference two lists, outputs IPs common to both lists .SH "AUTHOR" .PP This manual page was written by Ryan Finnie ryan@finnie.org for the \fBDebian\fP system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 any later version published by the Free Software Foundation. .PP On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .\" created by instant / docbook-to-man, Sun 04 Sep 2011, 13:49 debian/control0000664000000000000000000000206412237750145010603 0ustar Source: grepcidr Section: net Priority: optional Maintainer: Ryan Finnie Build-Depends: debhelper (>= 7.0.50~) Standards-Version: 3.9.4 Homepage: http://www.pc-tools.net/unix/grepcidr/ Vcs-Browser: https://code.launchpad.net/~fo0bar/grepcidr/grepcidr-pkg-debian Vcs-Bzr: http://bazaar.launchpad.net/~fo0bar/grepcidr/grepcidr-pkg-debian Package: grepcidr Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Description: Filter IP addresses matching IPv4 CIDR/network specification grepcidr can be used to filter a list of IP addresses against one or more Classless Inter-Domain Routing (CIDR) specifications, or arbitrary networks specified by an address range. As with grep, there are options to invert matching and load patterns from a file. grepcidr is capable of comparing thousands or even millions of IPs to networks with little memory usage and in reasonable computation time. . grepcidr has endless uses in network software, including: mail filtering and processing, network security, log analysis, and many custom applications. debian/rules0000775000000000000000000000077012237751176010267 0ustar #!/usr/bin/make -f # -*- makefile -*- # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS) CFLAGS:=$(shell dpkg-buildflags --get CFLAGS) LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS) %: dh $@ override_dh_auto_build: $(MAKE) CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" override_dh_auto_install: $(MAKE) install DESTDIR=$(CURDIR)/debian/grepcidr PREFIX=/usr override_dh_installman: dh_installman debian/grepcidr.1 debian/compat0000664000000000000000000000000212237745140010373 0ustar 7 debian/copyright0000664000000000000000000000313211630761601011123 0ustar This package was debianized by Ryan Finnie on Thu, 5 Oct 2006 01:58:17 -0700. It was downloaded from http://www.pc-tools.net/unix/grepcidr/ Upstream Author: Jem Berkes Copyright: 2004-2005 Jem E. Berkes This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License with the Debian GNU/Linux distribution in file /usr/share/common-licenses/GPL-2; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. On Debian systems, the complete text of the GNU General Public License can be found in `/usr/share/common-licenses/GPL-2'. getopt.c is Copyright 1987-1996, 1998-2002, Free Software Foundation, Inc. and is licensed under the GPL, see above. getopt.h is Copyright 1989-1994, 1996-1999, 2001, Free Software Foundation, Inc. and is licensed under the GPL, see above. getopt.c and getopt.h are not used in Debian's grepcidr binary packages (glibc built-in getopt is used instead), but are nevertheless retained in the source packaging. The Debian packaging is 2006, Ryan Finnie and is licensed under the GPL, see above. debian/docs0000664000000000000000000000000711561142413010036 0ustar README debian/source/0000775000000000000000000000000012237750222010472 5ustar debian/source/format0000664000000000000000000000001411630756565011714 0ustar 3.0 (quilt) debian/source/options0000664000000000000000000000014612237750222012111 0ustar # Ignore VCS files (non-native packages) diff-ignore # Ignore VCS files (native packages) #tar-ignore debian/grepcidr.sgml.README0000664000000000000000000000045011630762357012620 0ustar The manpage grepcidr.1 has been pre-compiled from grepcidr.sgml to remove the need for docbook-to-man during each build. If a change is needed to the manpage, edit it, install docbook-to-man, and run: docbook-to-man debian/grepcidr.sgml > debian/grepcidr.1 and ship the resulting files. debian/grepcidr.sgml0000664000000000000000000001356011561142413011656 0ustar manpage.1'. You may view the manual page with: `docbook-to-man manpage.sgml | nroff -man | less'. A typical entry in a Makefile or Makefile.am is: manpage.1: manpage.sgml docbook-to-man $< > $@ The docbook-to-man binary is found in the docbook-to-man package. Please remember that if you create the nroff version in one of the debian/rules file targets (such as build), you will need to include docbook-to-man in your Build-Depends control field. --> Ryan"> Finnie"> October 5, 2006"> 1"> ryan@finnie.org"> GREPCIDR"> Debian"> GNU"> GPL"> ]>
&dhemail;
&dhfirstname; &dhsurname; 2006 &dhusername; &dhdate;
&dhucpackage; &dhsection; &dhpackage; Filter IP addresses matching IPv4 CIDR/network specification &dhpackage; | DESCRIPTION This manual page documents briefly the &dhpackage; command. This manual page was written for the &debian; distribution because the original program does not have a manual page. &dhpackage; can be used to filter a list of IP addresses against one or more Classless Inter-Domain Routing (CIDR) specifications, or arbitrary networks specified by an address range. As with grep, there are options to invert matching and load patterns from a file. grepcidr is capable of comparing thousands or even millions of IPs to networks with little memory usage and in reasonable computation time. OPTIONS Show software version Display count of the matching lines, instead of showing the lines Invert the sense of matching, to select non-matching IP addresses Specify pattern(s) on command-line Obtain CIDR and range pattern(s) from file EXAMPLES grepcidr -f ournetworks blocklist > abuse.log Find our customers that show up in blocklists grepcidr 127.0.0.0/8 iplog Searches for any localnet IP addresses inside the iplog file grepcidr "192.168.0.1-192.168.10.13" iplog Searches for IPs matching indicated range in the iplog file script | grepcidr -vf whitelist > blacklist Create a blacklist, with whitelisted networks removed (inverse) grepcidr -f list1 list2 Cross-reference two lists, outputs IPs common to both lists AUTHOR This manual page was written by &dhusername; &dhemail; for the &debian; system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the &gnu; General Public License, Version 2 any later version published by the Free Software Foundation. On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL.
debian/changelog0000664000000000000000000000316412237751161011053 0ustar grepcidr (1.3-6) unstable; urgency=low * Lintian cleanup: * ancient-standards-version * dm-upload-allowed-is-obsolete * hardening-no-relro * Add Vcs information * Enable XZ-compressed deb -- Ryan Finnie Sun, 10 Nov 2013 18:37:30 +0000 grepcidr (1.3-5) unstable; urgency=low * Housekeeping release (no user-visible changes) * Switch to dpkg-source 3.0 (quilt) format * Converted debian/rules to unified dh * Bumped debian/compat to 7 * Adjusted debian/copyright (removed '(C)') * Added debian/watch file * Removed Build-Depends: docbook-to-man; debian/grepcidr.1 is now pre-compiled (with included source and README for manual regeneration) -- Ryan Finnie Sun, 04 Sep 2011 13:59:04 -0700 grepcidr (1.3-4) unstable; urgency=low * Dm-Upload-Allowed changed to XS-Dm-Upload-Allowed so it may be exported to the .dsc. -- Ryan Finnie Mon, 26 Nov 2007 22:43:39 -0800 grepcidr (1.3-3) unstable; urgency=low * 01_makefile.dpatch: Removed forced strip. (Closes: #437089) * 01_makefile.dpatch: Changed -O3 to -O2. * debian/rules: errors on "make clean" no longer ignored (Lintian debian-rules-ignores-make-clean-error). -- Ryan Finnie Mon, 26 Nov 2007 02:14:59 -0800 grepcidr (1.3-2) unstable; urgency=low * debian/control: Added "Dm-Upload-Allowed: yes" for debian-maintainer Ryan Finnie. -- Ryan Finnie Sat, 24 Nov 2007 23:02:06 -0800 grepcidr (1.3-1) unstable; urgency=low * Initial release (Closes: #391168) -- Ryan Finnie Thu, 5 Oct 2006 01:58:17 -0700 debian/patches/0000775000000000000000000000000012237746044010630 5ustar debian/patches/series0000664000000000000000000000005611630756715012050 0ustar 01_makefile.patch 02_regex-glibc-getopt.patch debian/patches/02_regex-glibc-getopt.patch0000775000000000000000000000645311630757357015662 0ustar ## regex-glibc-getopt.patch by Ryan Finnie This patch contains two modifications. First, grepcidr.c is modified to use glibc's built-in getopt, rather than the getopt provided with the tarball. Second, regular expression support is added. A description of the regex patch by the original patch author is provided below. These two patches were combined because patch(1) does not seem to be able to handle the two "conflicting" changes when separated. ---------------------------------------------------------------------- Date: Fri, 29 Apr 2005 19:44:05 -0700 From: Jeff Makey The patch included below adds regular expression processing to allow grepcidr to find IP addresses anywhere on the input. Tested against the README file shipped with grepcidr-1.3, the first command below shows one line of output and the second correctly shows none: grepcidr 192.168.0.0/20 README grepcidr 192.168.16.0/20 README My changes work on Red Hat Linux 9.0, Sun Solaris, SGI IRIX, and IBM AIX. It should be possible to use regular expression processing and avoid calling sscanf() in the ip_to_uint() function, but it may not be worth the effort. Note that for a number the source lines the only thing I changed is the indenting. After applying the patch use "diff -w" to see just the coding changes. Thanks for writing grepcidr. Feel free to include this change in the next release. :: Jeff Makey jeff@sdsc.edu diff -ruN grepcidr-1.3-orig/grepcidr.c grepcidr-1.3/grepcidr.c --- grepcidr-1.3-orig/grepcidr.c 2005-04-23 15:00:16.000000000 -0700 +++ grepcidr-1.3/grepcidr.c 2006-10-05 01:42:24.000000000 -0700 @@ -25,7 +25,8 @@ #include #include #include -#include "getopt.h" +#include +#include #define EXIT_OK 0 #define EXIT_NOMATCH 1 @@ -164,6 +165,7 @@ char line[MAXFIELD]; int foundopt; int anymatch = 0; /* did anything match? for exit code */ + static regex_t preg; /* compiled regular expression for IPs */ if (argc == 1) { @@ -272,22 +274,35 @@ } } + /* Compile the regular expression for matching IP addresses */ + if (regcomp(&preg, "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+", REG_EXTENDED) != 0) + { + (void)fputs("regcomp() failed\n", stderr); + return EXIT_ERROR; + } + /* Match IPs from input stream to network patterns */ while (fgets(line, sizeof(line), inp_stream)) { struct netspec key; - if ((key.min=ip_to_uint(line))) + regoff_t offset; + regmatch_t pmatch; + for (offset = 0; regexec(&preg, &line[offset], 1, &pmatch, 0) == 0; offset += pmatch.rm_eo) { - int match = 0; - if (bsearch(&key, array, patterns, sizeof(struct netspec), netsearch)) - match = 1; - if (invert ^ match) + if ((key.min=ip_to_uint(&line[offset + pmatch.rm_so]))) { - anymatch = 1; - if (counting) - counting++; - else - printf("%s", line); + int match = 0; + if (bsearch(&key, array, patterns, sizeof(struct netspec), netsearch)) + match = 1; + if (invert ^ match) + { + anymatch = 1; + if (counting) + counting++; + else + printf("%s", line); + break; + } } } } @@ -297,6 +312,7 @@ fclose(inp_stream); if (array) free(array); + regfree(&preg); if (counting) printf("%u\n", counting-1); debian/patches/01_makefile.patch0000664000000000000000000000151012237746044013723 0ustar ## makefile.patch by Ryan Finnie Index: grepcidr-1.3/Makefile =================================================================== --- grepcidr-1.3.orig/Makefile 2005-04-20 03:19:14.000000000 +0000 +++ grepcidr-1.3/Makefile 2013-11-10 18:10:38.595521231 +0000 @@ -3,21 +3,18 @@ # # Set to where you'd like grepcidr installed -INSTALLDIR=/usr/local/bin - -# Set to your favorite C compiler and flags -CC=gcc -CFLAGS=-s -O3 -Wall -pedantic - +PREFIX=/usr/local +BIN=$(PREFIX)/bin # End of settable values -grepcidr: - $(CC) $(CFLAGS) -o grepcidr grepcidr.c getopt.c +grepcidr: grepcidr.c + $(CC) $(CPPFLAGS) $(CFLAGS) -o grepcidr $(LDFLAGS) grepcidr.c all: grepcidr install: grepcidr - cp grepcidr $(INSTALLDIR) + install -d $(DESTDIR)$(BIN) + install ./grepcidr $(DESTDIR)$(BIN) clean: rm -f grepcidr *.o