The recent thread on CIDR aggregation cleanup scripts reminds me that I'm looking for a similarly efficient implementation of a related tool. (I'm gearing up to write my own in Perl, but don't want to reinvent the wheel.) I'd like a fast, Unix-pipeline-ready tool that *replaces* all IPs within that range with a supplied string, using a simple config file as input, and ideally with autodetection of IP-address "word" boundaries, as in: $ cat cidr-replace.cfg 105.170.75.0/24|[Unitel] 209.112.128.0/18|[ACS] 209.165.128.0/18|[GCI] 192.0.2.0/24|[TEST-NET-1] 198.51.100.0/24|[TEST-NET-2] 203.0.113.0/24|[TEST-NET-3] $ echo "source,data1,data2,209.112.130.2,data3" | cidr-replace cidr-replace.cfg source,data1,data2,[ACS],data3 And I know this is kludgy, but it would also be useful for quick-and-dirty work if it had a flag to "append" the string using a known delimiter, as in: $ echo "source,data1,data2,209.112.130.2,data3" | cidr-replace --append ',' cidr-replace.cfg source,data1,data2,209.112.130.2,[ACS],data3 (But I'm happy to hack that last functionality into an existing script.) -- Royce
This is what I have done using R: https://github.com/meekj/netblockr I still use similar tools in Perl with Net::Netmask Jon On Fri, Oct 2, 2020 at 11:50 AM Royce Williams <royce@techsolvency.com> wrote:
The recent thread on CIDR aggregation cleanup scripts reminds me that I'm looking for a similarly efficient implementation of a related tool. (I'm gearing up to write my own in Perl, but don't want to reinvent the wheel.)
I'd like a fast, Unix-pipeline-ready tool that *replaces* all IPs within that range with a supplied string, using a simple config file as input, and ideally with autodetection of IP-address "word" boundaries, as in:
$ cat cidr-replace.cfg 105.170.75.0/24|[Unitel] <http://105.170.75.0/24%7C%5BUnitel%5D> 209.112.128.0/18|[ACS] <http://209.112.128.0/18%7C%5BACS%5D> 209.165.128.0/18|[GCI] <http://209.165.128.0/18%7C%5BGCI%5D> 192.0.2.0/24|[TEST-NET-1] <http://192.0.2.0/24%7C%5BTEST-NET-1%5D> 198.51.100.0/24|[TEST-NET-2] <http://198.51.100.0/24%7C%5BTEST-NET-2%5D> 203.0.113.0/24|[TEST-NET-3] <http://203.0.113.0/24%7C%5BTEST-NET-3%5D>
$ echo "source,data1,data2,209.112.130.2,data3" | cidr-replace cidr-replace.cfg source,data1,data2,[ACS],data3
And I know this is kludgy, but it would also be useful for quick-and-dirty work if it had a flag to "append" the string using a known delimiter, as in:
$ echo "source,data1,data2,209.112.130.2,data3" | cidr-replace --append ',' cidr-replace.cfg source,data1,data2,209.112.130.2,[ACS],data3
(But I'm happy to hack that last functionality into an existing script.)
-- Royce
participants (2)
-
Jon Meek
-
Royce Williams