代码语言:javascript复制
#!/bin/bash
for((i=3;i ;i>1))
do
catip=(`netstat -ano | grep tcp | grep -v -E "127.0.0.1|100.100|0.0.0.0" | grep -v ":::"| awk -F" " '{print $5}' | sort | uniq -c | awk -F" " '{print $2}' | awk -F":" '{print $1}'`); echo ${catip[*]}
for j in ${catip[*]}
do
catiptxt=$(cat 2.txt | grep $j | wc -l)
if [ $catiptxt -lt 1 ]
then
echo $j >> 2.txt
echo $j "==========================》已经成功写入文件"
else
echo "IP : $j 已经存在"
fi
done
sleep 1
done