]> gitweb.michael.orlitzky.com - hath.git/blob - doc/man1/hath.1
Add tests for the --barriers option.
[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|reversed\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 .IP \(bu
29 Find their associated PTR records.
30 .P
31 Hath does just that. It takes as its input (via stdin, or a file with
32 the -i parameter) a list of CIDR blocks.
33 .SH MODES
34 .P
35 Hath has several modes:
36 .IP \(bu 2
37 \fBRegexed\fR
38 .P
39 This computes a (Perl-compatible) regular expression matching
40 the input CIDR blocks. It's the default mode of operation.
41 .P
42 .nf
43 .I $ hath <<< \(dq10.0.0.0/29 10.0.0.8/29\(dq
44 ((10)\.(0)\.(0)\.(0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15))
45 .fi
46 .IP \(bu 2
47 \fBReduced\fR
48 .P
49 This combines small blocks into larger ones where possible, and
50 eliminates redundant blocks. The output should be equivalent to
51 the input, though.
52 .P
53 .nf
54 .I $ hath reduced <<< \(dq10.0.0.0/24 10.0.1.0/24\(dq
55 10.0.0.0/23
56 .fi
57 .IP \(bu 2
58 \fBDuped\fR
59 .P
60 Shows only the blocks that would be removed by reduce; that is, it
61 shows the ones that would get combined into larger blocks or are
62 simply redundant.
63 .P
64 .nf
65 .I $ hath duped <<< \(dq10.0.0.0/24 10.0.1.0/24\(dq
66 10.0.0.0/24
67 10.0.1.0/24
68 .fi
69 .IP \(bu 2
70 \fBDiffed\fR
71 .P
72 Shows what would change if you used reduce. Uses diff-like
73 notation.
74 .P
75 .nf
76 .I $ hath diffed <<< \(dq10.0.0.0/24 10.0.1.0/24\(dq
77 -10.0.0.0/24
78 -10.0.1.0/24
79 +10.0.0.0/23
80 .fi
81 .IP \(bu 2
82 \fBListed\fR
83 .P
84 List the IP addresses contained within the given CIDRs.
85 .P
86 .nf
87 .I $ hath listed <<< \(dq192.168.0.240/29\(dq
88 192.168.0.240
89 192.168.0.241
90 192.168.0.242
91 192.168.0.243
92 192.168.0.244
93 192.168.0.245
94 192.168.0.246
95 192.168.0.247
96 .fi
97 .IP \(bu 2
98 \fBReversed\fR
99 .P
100 Perform reverse DNS (PTR) lookups on the IP addresses contained within
101 the given CIDRs.
102 .P
103 .nf
104 .I $ hath reversed <<< \(dq198.41.0.4/30\(dq
105 198.41.0.4: a.root-servers.net.
106 198.41.0.5:
107 198.41.0.6: rs.internic.net.
108 198.41.0.7:
109 .fi
110 .P
111 The DNS lookups are usually the bottleneck for this mode, but we can
112 perform them in parallel. Simply pass the number of threads to the GHC
113 runtime on the command line; for example, the following will perform
114 25 lookups in parallel:
115 .P
116 .nf
117 .I $ hath reversed +RTS -N25 <<< \(dq198.41.0.4/24\(dq
118 198.41.0.4: a.root-servers.net.
119 198.41.0.5:
120 198.41.0.6: rs.internic.net.
121 \(pc\(pc\(pc
122 .fi
123
124 .SH OPTIONS
125
126 .IP \fB\-\-barriers\fR,\ \fB\-b\fR
127 (regexed mode only) place barriers in front/back of the regex to
128 prevent e.g. '127.0.0.1' from matching '127.0.0.100'. The downside is
129 that the resulting regexp will match something that is not an IP
130 address, and this messes up e.g. \fIgrep -o\fR.
131
132 .P
133 Without \fB\-\-barriers\fR, you can match things you shouldn't:
134
135 .nf
136 .I $ echo \(dq127.0.0.100\(dq | grep -P $(hath <<< \(dq127.0.0.1/32\(dq)
137 127.0.0.100
138 .fi
139
140 .P
141 Using \fB\-\-barriers\fR can prevent this:
142
143 .nf
144 .I $ echo \(dq127.0.0.100\(dq | grep -P $(hath -b <<< \(dq127.0.0.1/32\(dq)
145 .I $ echo $?
146 1
147 .fi
148
149 .P
150 But, this may also cause the regex to match something that isn't an IP
151 address:
152
153 .nf
154 .I $ echo \(dqx127.0.0.1x\(dq | grep -Po $(hath -b <<< \(dq127.0.0.1/32\(dq)
155 x127.0.0.1x
156 .fi