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() {
# or: get_ipv4_list_bulk domains.txt
get_ipv4_list_bulk()
{
# read from file arg or stdin
local input=$(mktemp)
local domains=$(mktemp)
local adns_out=$(mktemp)
trap "rm -f $domains $adns_out" RETURN
# Read domains, skip IPs (output them directly)
while read -r entry ; do
[ -z "$entry" ] && continue
if is_ipv4 "$entry" ; then
echo "$entry"
else
echo "$entry" >> "$domains"
fi
done < "${1:-/dev/stdin}"
trap "rm -f $input $domains $adns_out" RETURN
# Save input, strip empty lines and comments
grep -v '^#\|^$' < "${1:-/dev/stdin}" > "$input"
# Output IPs/subnets directly (fast grep, no per-line bash loop)
grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]' "$input"
# Collect non-IP entries as domains to resolve
grep -vE '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]' "$input" > "$domains"
[ -s "$domains" ] || return 0
......@@ -107,19 +106,19 @@ get_ipv4_list_bulk()
# or: get_ipv6_list_bulk domains.txt
get_ipv6_list_bulk()
{
local input=$(mktemp)
local domains=$(mktemp)
local adns_out=$(mktemp)
trap "rm -f $domains $adns_out" RETURN
# Read domains, skip IPs (output them directly)
while read -r entry ; do
[ -z "$entry" ] && continue
if is_ipv6 "$entry" ; then
echo "$entry"
elif ! is_ipv4 "$entry" ; then
echo "$entry" >> "$domains"
fi
done < "${1:-/dev/stdin}"
trap "rm -f $input $domains $adns_out" RETURN
# Save input, strip empty lines and comments
grep -v '^#\|^$' < "${1:-/dev/stdin}" > "$input"
# Output IPv6 addresses directly
grep ':' "$input"
# Collect domains (not IPv4, not IPv6) to resolve
grep -v ':\|^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]' "$input" > "$domains"
[ -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