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]
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.)