#!/bin/bash
# Author: tianzhaogao (E-mail: 296862380@qq.coom)
#ip.txt 要匹配的ip文件
#okip.txt 匹配出的合法ip
rm -rf /root/test/okip.txt #初始化
touch /root/test/okip.txt #初始化
ip=$(cat ip.txt | grep "^[0-9]\{1,3\}\.[0-9]\{0,3\}\.[0-9]\{0,3\}\.[0-9]\{0,3\}")
for i in $ip
do
n1=$(echo "$i" | cut -d "." -f 1)
n2=$(echo "$i" | cut -d "." -f 2)
n3=$(echo "$i" | cut -d "." -f 3)
n4=$(echo "$i" | cut -d "." -f 4)
if [ "$n1" -lt 255 -a "$n2" -lt 255 -a "$n3" -lt 255 -a "$n4" -lt 255 ];then
echo "$i" >> okip.txt
fi
done