Eli Fulkerson .com HomeProjectsIps
 

ips

Description:

"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.

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

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'

Returns the number of matches.

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


License:

GPLv3

Download:

ips.exe for Cygwin - Compiled for Cygwin.

source - ips.cpp

ips for Linux: g++ -std=c++11 -o ips ips.cpp

ips for OSX: g++ -std=c++11 -o ips ips.cpp