firehol
firehol copied to clipboard
NFR: modify extract_ipv4_from_any_file() to work with busybox
Busybox does not support the '-P' argument to grep.
This code for extract_ipv4_from_any_file() finds all of the same IPs as the current code (for the lists enabled on my Edgerouter Lite...), but works using busybox:
tr '\r' '\n' | \
grep -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' |\
grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'|\
tr "." " " |\
while read o1 o2 o3 o4; do printf "$((10#$o1+0)).$((10#$o2+0)).$((10#$o3+0)).$((10#$o4+0))\n"; done
# diff -u update-ipsets- update-ipsets
--- update-ipsets- 2019-09-21 13:35:56.787854120 +0000
+++ update-ipsets 2019-09-21 13:42:22.343027962 +0000
@@ -3622,10 +3622,15 @@
}
extract_ipv4_from_any_file() {
- $GREP_CMD --text -oP "(^|[[:punct:]]|[[:space:]]|[[:cntrl:]])${IP4_MATCH}([[:punct:]]|[[:space:]]|[[:cntrl:]]|$)" |\
- $EGREP_CMD -v "${IP4_MATCH}\." |\
- $EGREP_CMD -v "\.${IP4_MATCH}" |\
- $GREP_CMD -oP "${IP4_MATCH}"
+ tr '\r' '\n' | \
+ $EGREP_CMD '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' |\
+ $EGREP_CMD -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'|\
+ tr "." " " |\
+ while read o1 o2 o3 o4
+ do
+ printf "$((10#$o1+0)).$((10#$o2+0)).$((10#$o3+0)).$((10#$o4+0))\n"
+ done
+
}
# process a list of IPs, IP ranges, hostnames