尝试过滤IP列表并拒绝列表“service_ip_list”中的IP 出于某些奇怪的原因,grepcidr只搜索列表“service_ip_list”中的前3个IP并忽略其余的,任何人都知道如何解决这个问题?
ip_filtering() { service_ip_list=("192.168.1.1" "192.168.1.2" "192.168.1.8" "192.168.1.80" "192.168.1.20" "192.168.1.200")
grepcidr "$service_ip_list" <(echo "$1") >/dev/null && \
echo "$1 is a Service IP" || \
echo $1 >> live_ser_list
}
for i in 192.168.1.{1..254}
do
ip_filtering $i & disown
done
答案 0 :(得分:0)
它不是grepcidr,如果在网络列表中匹配ip,如10.0.0.0/24,你可以使用/需要grepcidr, 但如果您需要通过拒绝数组中的IP来过滤IP,那么简单的解决方案就是:
#your array
declare -a service_ip_list=("192.168.1.1" "192.168.1.2" "192.168.1.8" "192.168.1.80" "192.168.1.20" "192.168.1.200")
ip_filtering () {
#this will match your IP to the IP's from the array
if [[ " ${service_ip_list[@]} " =~ " ${1} " ]]; then
#if found in array
echo "$1 is a Service IP"
else
#if not found in array
echo $1 >> live_ser_list
fi
}
# your IP source
for i in 192.168.1.{1..254}
do
ip_filtering $i & disown
done