shell 脚本判断ip

1.编写txt里面放入ip

[root@localhost ~]# vim ip.txt
192.168.177.1
192.168.177.2
192.168.177.3
192.168.177.4
192.168.177.5
192.168.177.6
172.168.177.8
127.0.0.1

2.编写脚本

[root@localhost ~]# vim if.sh

#!/bin/bash
ip=(`cat /root/ip.txt`)
for i in ${ip[*]}
do
        if [[ $i == "192"* ]]; then
                echo "$i is ok"
        else
                iptables -A INPUT -s $i -j DROP &> /dev/null
                echo "$i drop"
        fi
done

3.测试

[root@localhost ~]# sh if.sh

  

 

猜你喜欢

转载自www.cnblogs.com/wendyluo/p/13173648.html