Eli Fulkerson .com HomeProjectsIps
 

ips

"ips" is a console program that plucks IPv4 and IPv6 addresses out of stdin. You use it like you would use grep, but for IP addresses. (IPs, especially abbreviated IPv6s are notoriously obnoxious to pick out with regular expressions). In particular, ips is capable of doing IPv4 and IPv6 math and understands ranges both in the document you are searching and as a search term itself. I've tried to include the most common syntaxes for IP ranges, if you need another let me know.

The --cisco option will, in addition to whatever other context you have asked for, will return the first prior line to the matched line that does not have leading spaces. This has the effect of picking out the head of the stanza for cisco style configuration files. In 0.3 the --cisco option will additionally notice the 'object' and 'object-group' definitions that match your search terms and add the name of the object/object-group as a string match to your results.

You might also be interested in this program's baby brother: xips. Xips uses the same ip matching engine to expand/condense lists of ip addresses.

Usage:


Syntax: your_command | ips [-4] [-6] [-v] [-%] [-s] [-q] [-c lines] [-v]  ip (or range)

Eats STDIN, outputs lines containing IP addresses or matching specified IP or range.
Options:
 -4     : match IPv4 addresses only
 -6     : match IPv6 addresses only
 -%     : include IPv6 scope
 -s     : strict, require IPs to be surrounded by whitespace
 -n     : output line numbers
 -q     : quiet, no output
 -c X   : print X lines of context.  (Also --context)
 -b     : 'basic' mode, one ip per line, no context (--basic)
 -v     : Display version information
 --cisco:  Include the last non-indented line when printing context
 --aton : Use "old" inet_aton behavior.  For instance, 10.5 is another name for 10.0.0.5

Shorthand:
 A,-B,-C,-D,-E    : Shorthand to match addresses in the classical IP address classes.  Also --multicast, --experimental for D and E
 --loopback       : Shorthand to match 127.0.0.0 through 127.255.255.255
 --10,--192,--172 : Shorthand to match RFC 1918 address ranges

IP/Range Syntax:
 192.168.1.1
 192.168.1.1-192.168.1.255
 192.168.1.1/24
 192.168.1.1/C
 '192.168.1.1 255.255.255.0'

Action shots:


$ipconfig |./ips
   IPv6 Address. . . . . . . . . . . : (REDACTED):5937:92d0:87f1:8eac
   Temporary IPv6 Address. . . . . . : (REDACTED):355c:a5d8:4249:2704
   Temporary IPv6 Address. . . . . . : (REDACTED):4da8:dd2:2107:1717
   Temporary IPv6 Address. . . . . . : (REDACTED):6199:a955:c19b:dd21
   Temporary IPv6 Address. . . . . . : (REDACTED):7449:e249:f999:f17b
   Temporary IPv6 Address. . . . . . : (REDACTED):a453:97e8:1f27:69d8
   Temporary IPv6 Address. . . . . . : (REDACTED):a99c:3441:6557:dd3
   Link-local IPv6 Address . . . . . : (REDACTED):92d0:87f1:8eac%7
   IPv4 Address. . . . . . . . . . . : 192.168.2.20
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : (REDACTED):fe00:df0b%7
                                       192.168.2.1



$cat asa_example.txt |ips --cisco 10.20.30.188-10.20.30.192
name 10.20.30.189 example1
name 10.20.30.190 example2
name 10.20.30.188 example3
interface Ethernet0/2.444
 ...
 ip address 10.20.30.129 255.255.255.128
 ...
object-group network example_object_group
 ...
 network-object host 10.20.30.189
 network-object host 10.20.30.190
 ...
object-group network example_object_group2
 ...
 network-object 10.20.30.128 255.255.255.128
 ...
object-group network example_object_group3
 ...
 network-object host 10.20.30.192
 ...
object-group network example_object_group4
 ...
 network-object host 10.20.30.188
 network-object host 10.20.30.189
 ...
access-list outside_in extended permit tcp any host 10.20.30.191 eq 210
access-list vlan1_in extended permit udp 10.20.30.128 255.255.255.128 host 10.20.30.244 eq tftp
access-list vlan2_in extended deny ip any 10.20.30.128 255.255.255.128
static (dmz,outside) 10.20.30.188 10.20.30.188 netmask 255.255.255.255
static (dmz,outside) 10.20.30.189 10.20.30.189 netmask 255.255.255.255
static (dmz,outside) 10.20.30.190 10.20.30.190 netmask 255.255.255.255
static (inside,outside) 10.20.30.191 172.20.141.126 netmask 255.255.255.255
route outside 0.0.0.0 0.0.0.0 10.20.99.249 1


Downloads:


Listing directory https://download.elifulkerson.com/files/ips/0.7: Makefile June 16 2017 14:16:12 144 makefile script, ASCII text cygwin-dlls-for-ips.zip January 06 2018 22:05:47 1586300 Zip archive data, at least v2.0 to extract cygwin-dlls-for-ips.zip.asc January 06 2018 22:09:08 801 GnuPG signature cygwin-dlls-for-ips.zip.md5 January 06 2018 22:09:08 58 MD5 checksum cygwin-dlls-for-ips.zip.sha1 January 06 2018 22:09:08 66 SHA1 checksum cygwin-dlls-for-ips.zip.sha256 January 06 2018 22:09:08 90 SHA256 checksum cygwin-dlls-for-ips.zip.sha512 January 06 2018 22:09:08 154 SHA512 checksum ips.cpp July 05 2017 19:37:57 45177 C++ source, ASCII text, with very long lines, with CRLF line terminators ips.cpp.asc July 10 2017 13:56:17 801 GnuPG signature ips.cpp.md5 July 10 2017 13:56:17 42 MD5 checksum ips.cpp.sha1 July 10 2017 13:56:17 50 SHA1 checksum ips.cpp.sha256 July 10 2017 13:56:17 74 SHA256 checksum ips.cpp.sha512 July 10 2017 13:56:17 138 SHA512 checksum ips.exe January 06 2018 22:07:29 270009 PE32+ executable (console) x86-64, for MS Windows ips.exe.asc January 06 2018 22:09:21 801 GnuPG signature ips.exe.md5 January 06 2018 22:09:21 42 MD5 checksum ips.exe.sha1 January 06 2018 22:09:21 50 SHA1 checksum ips.exe.sha256 January 06 2018 22:09:21 74 SHA256 checksum ips.exe.sha512 January 06 2018 22:09:21 138 SHA512 checksum maketests.py July 05 2017 19:16:00 13386 Python script, ASCII text executable ↩ Browse the download server

To compile: g++ -std=c++11 -o ips ips.cpp

Updates:

Update: June 12 2017, v0.5. Bug fixes. Support of '192.168.1.X-Y' syntax in the input file.

Update: June 26 2017, v0.6. More bug fixes. Moved to new download server.

Update: July 10 2017, v0.7. I don't remember what I changed. I wrote this update in Jan 2018 when I added compiled versions to this update.

Note to self: (todo) Need to add 'detection of the IPv6 autoconfiguration version of a matching IPv4 address'.

License:

GPLv3

See also:

xips - an ip address expander/summarizer that uses the same parsing logic as ips