Skip to content

Commit 7f0e9e7

Browse files
Merge pull request #20 from nicholaschiasson/patch/update-readme
Updating examples section of README.md
2 parents f6d78ff + fe73e69 commit 7f0e9e7

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ Options:
5050
-V, --version Print version`
5151
```
5252

53-
### Example
53+
### Examples
54+
55+
#### Computing a specific set of CIDRs within 10.0.0.0/8, excluding some subranges, and including a subrange of one that was excluded
5456

5557
```
5658
fcidr 10.0.0.0/8 difference 10.0.64.0/20 | fcidr difference 10.0.82.0/24 | fcidr union 10.0.82.74/31
@@ -72,6 +74,8 @@ fcidr 10.0.0.0/8 difference 10.0.64.0/20 | fcidr difference 10.0.82.0/24 | fcidr
7274
10.128.0.0/9
7375
```
7476

77+
#### Inverting the previous result
78+
7579
```
7680
fcidr 10.0.0.0/8 difference 10.0.64.0/20 | fcidr difference 10.0.82.0/24 | fcidr union 10.0.82.74/31 | fcidr complement
7781
0.0.0.0/5
@@ -92,7 +96,9 @@ fcidr 10.0.0.0/8 difference 10.0.64.0/20 | fcidr difference 10.0.82.0/24 | fcidr
9296
128.0.0.0/1
9397
```
9498

95-
Alternative concise syntax:
99+
#### Alternative concise syntax
100+
101+
Note these symbols may not play nice with your shell, so you can quote them if you want, for example `fcidr "!"`).
96102

97103
```
98104
fcidr 10.0.0.0/8 + 127.0.0.0/16 | fcidr - 10.64.0.0/16 | fcidr !
@@ -120,6 +126,8 @@ fcidr 10.0.0.0/8 + 127.0.0.0/16 | fcidr - 10.64.0.0/16 | fcidr !
120126
128.0.0.0/1
121127
```
122128

129+
#### Check if an IP is within a CIDR
130+
123131
```
124132
fcidr 255.0.0.0/16 contains "255.0.1.2/32" && echo Woohoo!
125133
Woohoo!
@@ -130,6 +138,20 @@ echo 255.0.0.0/16 | fcidr contains "255.1.1.2/32" && echo Woohoo!
130138
Error: "not a superset of 255.1.1.2/32"
131139
```
132140

141+
#### Check if a CIDR is within any of a large set of CIDRs
142+
143+
Expanding upon the previous example, thanks to Amazon publishing a JSON formatted list of their public IP ranges, we can check if an IP or CIDR effectively is owned by Amazon. As long as we can get the list of ranges separated by new lines, piping that to `fcidr` makes the task trivial.
144+
145+
```
146+
curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[].ip_prefix' | fcidr contains 52.43.76.84/30 && echo "This CIDR is within an Amazon range."
147+
This CIDR is within an Amazon range.
148+
```
149+
150+
```
151+
curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[].ip_prefix' | fcidr contains 62.43.76.0/24 && echo "This CIDR is within an Amazon range."
152+
Error: "not a superset of 62.43.76.0/24"
153+
```
154+
133155
## Development
134156

135157
### Prerequisites

0 commit comments

Comments
 (0)