Skip to content

Instantly share code, notes, and snippets.

@scue
Last active August 29, 2015 14:20
Show Gist options
  • Save scue/6f6d02738f4e4e3474c3 to your computer and use it in GitHub Desktop.
Save scue/6f6d02738f4e4e3474c3 to your computer and use it in GitHub Desktop.
opengrok assess control (with iptables rule)
#!/bin/bash -
#===============================================================================
#
# FILE: opengrok_rules.sh
#
# USAGE: ./opengrok_rules.sh
#
# DESCRIPTION:
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: lwq (28120), scue@vip.qq.com
# ORGANIZATION:
# CREATED: 05/07/15 09:58:49 HKT
# REVISION: ---
#===============================================================================
project42_ipaddress_list=( \
123.123.136.232 \
123.123.136.231 \
)
project43_ipaddress_list=( \
123.123.137.171 \
123.123.137.174 \
)
ipaddress_list=( \
${project42_ipaddress_list[@]} \
${project43_ipaddress_list[@]} \
123.123.139.70 \
)
add_rules(){
local ipaddress=$1
# tcp
sudo iptables -C INPUT -s $ipaddress -p tcp --dport 8080 -j ACCEPT || \
sudo iptables -I INPUT -s $ipaddress -p tcp --dport 8080 -j ACCEPT
# udp
sudo iptables -C INPUT -s $ipaddress -p udp --dport 8080 -j ACCEPT || \
sudo iptables -I INPUT -s $ipaddress -p udp --dport 8080 -j ACCEPT
}
# 批量添加
for ip in ${ipaddress_list[@]} ; do
echo "Checking and add rule for $ip .."
add_rules $ip
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment