Commit f5f7f3c9 authored by Vitaly Lipatov's avatar Vitaly Lipatov

router/functions: replace while-read with grep for bulk IP/domain splitting

154k lines of ipresolve.lst made while-read loop extremely slow. Use grep to instantly separate IPs from domains. Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 60e7ed97
...@@ -62,20 +62,19 @@ cat_expanded() { ...@@ -62,20 +62,19 @@ cat_expanded() {
# or: get_ipv4_list_bulk domains.txt # or: get_ipv4_list_bulk domains.txt
get_ipv4_list_bulk() get_ipv4_list_bulk()
{ {
# read from file arg or stdin local input=$(mktemp)
local domains=$(mktemp) local domains=$(mktemp)
local adns_out=$(mktemp) local adns_out=$(mktemp)
trap "rm -f $domains $adns_out" RETURN trap "rm -f $input $domains $adns_out" RETURN
# Read domains, skip IPs (output them directly) # Save input, strip empty lines and comments
while read -r entry ; do grep -v '^#\|^$' < "${1:-/dev/stdin}" > "$input"
[ -z "$entry" ] && continue
if is_ipv4 "$entry" ; then # Output IPs/subnets directly (fast grep, no per-line bash loop)
echo "$entry" grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]' "$input"
else
echo "$entry" >> "$domains" # Collect non-IP entries as domains to resolve
fi grep -vE '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]' "$input" > "$domains"
done < "${1:-/dev/stdin}"
[ -s "$domains" ] || return 0 [ -s "$domains" ] || return 0
...@@ -107,19 +106,19 @@ get_ipv4_list_bulk() ...@@ -107,19 +106,19 @@ get_ipv4_list_bulk()
# or: get_ipv6_list_bulk domains.txt # or: get_ipv6_list_bulk domains.txt
get_ipv6_list_bulk() get_ipv6_list_bulk()
{ {
local input=$(mktemp)
local domains=$(mktemp) local domains=$(mktemp)
local adns_out=$(mktemp) local adns_out=$(mktemp)
trap "rm -f $domains $adns_out" RETURN trap "rm -f $input $domains $adns_out" RETURN
# Read domains, skip IPs (output them directly) # Save input, strip empty lines and comments
while read -r entry ; do grep -v '^#\|^$' < "${1:-/dev/stdin}" > "$input"
[ -z "$entry" ] && continue
if is_ipv6 "$entry" ; then # Output IPv6 addresses directly
echo "$entry" grep ':' "$input"
elif ! is_ipv4 "$entry" ; then
echo "$entry" >> "$domains" # Collect domains (not IPv4, not IPv6) to resolve
fi grep -v ':\|^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]' "$input" > "$domains"
done < "${1:-/dev/stdin}"
[ -s "$domains" ] || return 0 [ -s "$domains" ] || return 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment