4 hath \- Manipulate network blocks in CIDR notation
7 \fBhath\fR [\fBregexed|reduced|duped|diffed|listed\fR] [\fB\-hb\fR] \fI<input>\fR
10 The \fIinput\fR (stdin) should be a list of CIDR blocks, separated by
11 whitespace. Empty lines will be ignored, but otherwise, malformed
12 entries will cause an error to be displayed.
15 Hath is a Haskell program for working with network blocks in CIDR
16 notation. When dealing with blocks of network addresses, there are a
17 few things that one usually wants to do with them:
19 Create a regular expression matching the CIDR block(s). This is
20 because grep will throw up if you feed it CIDR.
22 Combine small blocks into larger ones. For example, if you have two
23 consecutive /24s, they might combine into a larger /23.
25 View the result of block combination in a useful way.
29 Hath does just that. It takes as its input (via stdin) a list of CIDR
33 Hath has several modes:
37 This computes a (Perl-compatible) regular expression matching
38 the input CIDR blocks. It's the default mode of operation.
41 .I $ echo \(dq10.0.0.0/29 10.0.0.8/29\(dq | hath
42 ((10)\.(0)\.(0)\.(15|14|13|12|11|10|9|8|7|6|5|4|3|2|1|0))
47 This combines small blocks into larger ones where possible, and
48 eliminates redundant blocks. The output should be equivalent to
52 .I $ echo \(dq10.0.0.0/24 10.0.1.0/24\(dq | hath reduced
58 Shows only the blocks that would be removed by reduce; that is, it
59 shows the ones that would get combined into larger blocks or are
63 .I $ echo \(dq10.0.0.0/24 10.0.1.0/24\(dq | hath duped
70 Shows what would change if you used reduce. Uses diff-like
74 .I $ echo \(dq10.0.0.0/24 10.0.1.0/24\(dq | hath diffed
82 List the IP addresses contained within the given CIDRs.
85 .I $ echo 192.168.0.240/29 | hath listed
97 Use the \(dqdig\(dq command to look up the PTR records for a netblock:
100 .I $ echo 198.41.0.4/30 | hath listed | xargs -I{} dig +noall +answer -x '{}'
101 4.0.41.198.in-addr.arpa. 897 IN PTR a.root-servers.net.
102 6.0.41.198.in-addr.arpa. 900 IN PTR rs.internic.net.
105 Sort the \(dqreduced\(dq output:
108 .I $ echo \(dq192.168.0.100/24 192.167.1.200/24\(dq | hath reduced | sort
113 Sorting the output only makes sense for the \(dqreduced\(dq mode. In
114 that mode, two output CIDRs cannot have same the numeric address and a
115 different mask: one of them would contain the other, and the redundant
116 one would be eliminated. As a result, there is no need for a special
117 CIDR sort; the lexical or numerical sort provided by the \(dqsort\(dq
118 utility will produce the same results as a more intelligent sort.
121 .IP \fB\-\-barriers\fR,\ \fB\-b\fR
124 Place barriers in front/back of the regex to prevent, for
125 example, '127.0.0.1' from matching '127.0.0.100'. The downside is that
126 the resulting regexp will match something that is not an IP address.
127 This can interfere with things like \fIgrep -o\fR.
129 Without \fB\-\-barriers\fR, you can match things you shouldn't:
132 .I $ echo 127.0.0.100 | grep -P $(echo 127.0.0.1/32 | hath)
136 Using \fB\-\-barriers\fR can prevent this:
139 .I $ echo 127.0.0.100 | grep -P $(echo 127.0.0.1/32 | hath -b)
144 But, this may also cause the regex to match something that isn't an IP
148 .I $ echo x127.0.0.1x | grep -Po $(echo 127.0.0.1/32 | hath -b)
152 .IP \fB\-\-normalize\fR,\ \fB\-n\fR
155 Normalize the output representation of CIDRs by zeroing the host
156 bits. This option only has an effect in \(dqreduced\(dq mode, because
157 in the \(dqduped\(dq or \(dqdiffed\(dq modes, it would be confusing to
158 see CIDRs that you did not input in the first place being removed.
161 .I $ echo 127.0.0.1/8 | hath reduced
163 .I $ echo 127.0.0.1/8 | hath reduced --normalize
168 Send bugs to michael@orlitzky.com.