]> gitweb.michael.orlitzky.com - hath.git/blob - doc/man1/hath.1
85978353ab0bdd6ff43dd2876d610ce561d697fe
[hath.git] / doc / man1 / hath.1
1 .TH hath 1
2
3 .SH NAME
4 hath \- Manipulate network blocks in CIDR notation
5 .SH SYNOPSIS
6
7 \fBhath\fR [\fBregexed|reduced|duped|diffed|listed\fR] [\fB\-hb\fR] \fI<input>\fR
8 .SH INPUT
9 .P
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.
13 .SH DESCRIPTION
14 .P
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:
18 .IP \(bu 2
19 Create a regular expression matching the CIDR block(s). This is
20 because grep will throw up if you feed it CIDR.
21 .IP \(bu
22 Combine small blocks into larger ones. For example, if you have two
23 consecutive /24s, they might combine into a larger /23.
24 .IP \(bu
25 View the result of block combination in a useful way.
26 .IP \(bu
27 List them.
28 .P
29 Hath does just that. It takes as its input (via stdin) a list of CIDR
30 blocks.
31 .SH MODES
32 .P
33 Hath has several modes:
34 .IP \(bu 2
35 \fBRegexed\fR
36
37 This computes a (Perl-compatible) regular expression matching
38 the input CIDR blocks. It's the default mode of operation.
39
40 .nf
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))
43 .fi
44 .IP \(bu 2
45 \fBReduced\fR
46
47 This combines small blocks into larger ones where possible, and
48 eliminates redundant blocks. The output should be equivalent to
49 the input, though.
50
51 .nf
52 .I $ echo \(dq10.0.0.0/24 10.0.1.0/24\(dq | hath reduced
53 10.0.0.0/23
54 .fi
55 .IP \(bu 2
56 \fBDuped\fR
57
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
60 simply redundant.
61
62 .nf
63 .I $ echo \(dq10.0.0.0/24 10.0.1.0/24\(dq | hath duped
64 10.0.0.0/24
65 10.0.1.0/24
66 .fi
67 .IP \(bu 2
68 \fBDiffed\fR
69
70 Shows what would change if you used reduce. Uses diff-like
71 notation.
72
73 .nf
74 .I $ echo \(dq10.0.0.0/24 10.0.1.0/24\(dq | hath diffed
75 -10.0.0.0/24
76 -10.0.1.0/24
77 +10.0.0.0/23
78 .fi
79 .IP \(bu 2
80 \fBListed\fR
81
82 List the IP addresses contained within the given CIDRs.
83
84 .nf
85 .I $ echo 192.168.0.240/29 | hath listed
86 192.168.0.240
87 192.168.0.241
88 192.168.0.242
89 192.168.0.243
90 192.168.0.244
91 192.168.0.245
92 192.168.0.246
93 192.168.0.247
94 .fi
95 .SH EXAMPLES
96 .P
97 Use the \(dqdig\(dq command to look up the PTR records for a netblock:
98
99 .nf
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.
103 .fi
104 .P
105 Sort the \(dqreduced\(dq output:
106
107 .nf
108 .I $ echo \(dq192.168.0.100/24 192.167.1.200/24\(dq | hath reduced | sort
109 192.167.1.200/24
110 192.168.0.100/24
111 .fi
112
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.
119 .SH OPTIONS
120
121 .IP \fB\-\-barriers\fR,\ \fB\-b\fR
122 (regexed mode only)
123
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.
128
129 Without \fB\-\-barriers\fR, you can match things you shouldn't:
130
131 .nf
132 .I $ echo 127.0.0.100 | grep -P $(echo 127.0.0.1/32 | hath)
133 127.0.0.100
134 .fi
135
136 Using \fB\-\-barriers\fR can prevent this:
137
138 .nf
139 .I $ echo 127.0.0.100 | grep -P $(echo 127.0.0.1/32 | hath -b)
140 .I $ echo $?
141 1
142 .fi
143
144 But, this may also cause the regex to match something that isn't an IP
145 address:
146
147 .nf
148 .I $ echo x127.0.0.1x | grep -Po $(echo 127.0.0.1/32 | hath -b)
149 x127.0.0.1x
150 .fi
151
152 .IP \fB\-\-normalize\fR,\ \fB\-n\fR
153 (reduced mode only)
154
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.
159
160 .nf
161 .I $ echo 127.0.0.1/8 | hath reduced
162 127.0.0.1/8
163 .I $ echo 127.0.0.1/8 | hath reduced --normalize
164 127.0.0.0/8
165 .fi
166 .SH BUGS
167
168 Send bugs to michael@orlitzky.com.