#!/bin/bash
iplist=(
10.0.0.0/8
172.16.0.0/12
172.32.0.0/16
192.168.0.0/16
61.187.53.128/25
175.6.15.0/24
123.59.21.0/24
113.247.251.0/26
58.20.34.192/26
113.247.251.128/27
113.247.251.160/27
218.76.45.96/27
110.53.162.224/27
113.247.232.112/28
119.39.39.128/26
124.232.146.128/26
119.39.39.136
124.232.146.140
123.59.23.184
203.187.176.82
123.59.21.117
124.250.52.47
175.6.15.89
175.6.15.207
123.57.80.40
123.56.255.8
47.93.215.93
81.70.217.217
81.70.217.71
81.70.217.61
152.136.67.117
47.93.254.187
152.136.150.118
10.50.100.42
10.43.43.46
10.43.1.233
10.200.130.31
106.8.131.29
116.132.219.218
111.63.205.58
111.63.205.96
106.8.131.208
116.132.218.57
123.182.51.51
116.132.216.187
111.63.205.32
)
for ip in "${iplist[@]}" ;do
    if [ $(iptables -vnL | grep "RH-Firewall-1-INPUT" | wc -l ) -gt 0 ];then
        if [ $(iptables -vnL RH-Firewall-1-INPUT | grep "$ip" | wc -l ) -eq 0 ];then
            iptables -I RH-Firewall-1-INPUT -s $ip -p tcp -m tcp --dport 22 -j ACCEPT 
        fi
        if [ $(iptables -vnL INPUT | grep RH-Firewall-1-INPUT | wc -l) -eq 0 ];then
            iptables -I INPUT -j RH-Firewall-1-INPUT
        fi
    else
        iptables -N RH-Firewall-1-INPUT 
        iptables -I INPUT -j RH-Firewall-1-INPUT 
        iptables -I RH-Firewall-1-INPUT -s $ip -p tcp -m tcp --dport 22 -j ACCEPT
    fi
    echo $ip
done
