生成一个ip.txt文件
判断:当ip为192开头的,显示这个ip是ok的,当ip为172开头的,就调用iptables drop掉
vim ip.txt
键入:
192.168.1.1
192.168.1.2
172.129.1.1
172.129.1.2
#!/bin/bash
# 用数组的方式输出ip.txt文件
ip=(`cat /root/ip.txt`)
# 循环遍历数组
for i in ${ip[@]}
do
# 开始判断IP是否为192开头的IP
if [[ $i == "192."* ]];then
echo "$i is OK"
else
# 使用iptables dorp掉IP
iptables -A INPUT -s $i -j OROP &>/dev/null
echo "$i 此IP以drop"
fi
done原文:https://www.cnblogs.com/sunjianlin/p/13169925.html