-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssh_ip_access.sh
executable file
·26 lines (26 loc) · 995 Bytes
/
ssh_ip_access.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/sh
#grep -E '^([0-2]?[0-9]?[0-9]\.){3}([0-2]?[0-9]?[0-9])$'
#grep -q -E '^([0-2]?[0-9]?[0-9](\.|$)){4}$' <<< "$2"
regex='^([0-2]?[0-9]?[0-9](\.|$)){4}$'
subnet='(^0+\.)|(\.0+$)'
if [[ "$2" =~ $regex ]] && ! [[ "$2" =~ $subnet ]] ; then
if iptables --line-numbers -nL INPUT |grep -E '[[:space:]]+ACCEPT[[:space:]]+' -- |grep -q -E "[[:space:]]+$2[[:space:]]+" -- ;then
echo "found"
if [[ "$1" == "-R" ]] ; then
iptables -D INPUT -p tcp -s $2 --dport 22 -j ACCEPT
echo "removed"
fi
else
echo "not found"
if [[ "$1" == "-A" ]] ; then
iptables -I INPUT -p tcp -s $2 --dport 22 -j ACCEPT
echo "added"
fi
fi
iptables --line-numbers -nL INPUT |grep -E '^[[:digit:]]+[[:space:]]+ACCEPT[[:space:]]+tcp' --
#iptables --line-numbers -nL INPUT |grep -E '^[[:digit:]]+[[:space:]]+ACCEPT[[:space:]]+tcp' --
#iptables --line-numbers -nL INPUT
#getent hosts birodb.com | awk -- '{ print $1 ; }'
else
echo "invalid ip value: $2"
fi