cli
cli copied to clipboard
IP expression resolver
I think this can technically be done in Python and other languages without any rocket science, but just throwing ideas here anyway:
An expression resolving subcommand that implements a very basic language specifically for text stream IP handling, kind of like awk
but specialized for IPs. It could support e.g.
- awk-like args after parsing streaming text input
- comparison (
<
,<=
,>
,>=
,==
) - overlap check (
OVERLAPS
) - contains check (
IN
) - bit-length check (
LEN
) - bitwise logic (
|
,&
,!
,^
, etc) - boolean logic (
AND
,OR
, etc) - ternary op (
<bool expr> ? <true case> : <false case>
)
The following example would output all CIDR (not IP/range) entries in column 2 of a TSV that overlap with 1.1.1.0/24
:
$ cat ip.tsv | ipinfo expr -d'\t' '$2 OVERLAPS 1.1.1.0/24 && isCidr($2) ? $2 : ""'
Most use cases can probably be done without a full expression resolver though, e.g. one tool to get all entries in column 2 of the TSV, piped into another tool like ipinfo tool overlap
, piped into a ipinfo tool filterCidr
, etc