Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- mc_port=25565
- users=('DerMetzgerFlo' 'pc')
- regex="^([[:alpha:]]+).*\((.*)\)$"
- ssh_users=()
- ips=()
- while read -r line ; do
- [[ $line =~ $regex ]]
- for i in "${users[@]}"
- do
- if [ "$i" == "${BASH_REMATCH[1]}" ] ; then
- ssh_users+=(${BASH_REMATCH[1]})
- ips+=(${BASH_REMATCH[2]})
- fi
- done
- done < <(who | grep -v localhost | grep -v "(:0)")
- #flush existing rules
- /sbin/iptables -F
- for i in "${!ssh_users[@]}"
- do
- #allow connection for user ${ssh_users[$i]} on ip ${ips[$i]}
- /sbin/iptables -A INPUT -p tcp --destination-port $mc_port -s ${ips[$i]} -j ACCEPT
- done
- #disallow all other connections
- /sbin/iptables -A INPUT -p tcp --destination-port $mc_port -j DROP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement