#!/bin/bash

ip=$1

#iptables -nvL INPUT --line-numbers | grep 212.7.218.54 | grep "$common_name" | cut -f1 -d" "

for rule_number in $(iptables -nvL INPUT --line-numbers | grep "212.7.218.54" | grep -w "dpt:22" | grep "$common_name" | cut -f1 -d" "); do 
	echo "/usr/sbin/iptables -I INPUT $rule_number -p tcp -m tcp -s $ip --dport 22 -j ACCEPT"
	/usr/sbin/iptables -I INPUT $rule_number -p tcp -m tcp -s $ip --dport 22 -j ACCEPT
done

for rule_number in $(iptables -nvL INPUT --line-numbers | grep "212.7.218.54" | grep -w "dpt:2202" | grep "$common_name" | cut -f1 -d" "); do 
	echo "/usr/sbin/iptables -I INPUT $rule_number -p tcp -m tcp -s $ip --dport 2202 -j ACCEPT"
	/usr/sbin/iptables -I INPUT $rule_number -p tcp -m tcp -s $ip --dport 2202 -j ACCEPT
done

/usr/sbin/iptables -nvL INPUT --line-numbers | grep -A 2 -B 1 "212.7.218.54"
