Xentrk
Part of the Furniture
Untested, remember adding an ipset might take time so dont rush it when testing.
Code:#!/bin/sh # Original script by swetoast. Updates by Neurophile & Octopus. # Revision 1 path=/opt/var/cache/malware-filter # Set your path here regexp=`echo "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"` # Dont change this value ipset -v | grep -i "v4" > /dev/null 2>&1 if [ $? -eq 0 ]; then ipsetv=4 lsmod | grep "ipt_set" > /dev/null 2>&1 || \ for module in ip_set ip_set_nethash ip_set_iphash ipt_set do insmod $module done else ipsetv=6 lsmod | grep "xt_set" > /dev/null 2>&1 || \ for module in ip_set ip_set_hash_net ip_set_hash_ip xt_set do insmod $module done fi case $(uname -m) in armv7l) MATCH_SET='--match-set' # Value for ARM Routers ;; mips) MATCH_SET='--set' # Value for Mips Routers ;; *) MATCH_SET='--match-set' # Value for ARM Routers ;; esac get_list () { mkdir -p $path wget -q --show-progress -i $path/malware-filter.list -O $path/malware-list.pre cat $path/malware-list.pre | grep -oE "$regexp" | sort -u >$path/malware-filter.txt } run_ipset () { get_list ipset -L malware-filter >/dev/null 2>&1 if [ $? -ne 0 ]; then if [ "$(ipset --swap malware-filter malware-filter 2>&1 | grep -E 'Unknown set|The set with the given name does not exist')" != "" ]; then path=/opt/var/cache/malware-filter ipset -N malware-filter hash:ip family inet hashsize 2048 maxelem 65536 for i in `cat $path/malware-filter.txt`; do ipset add malware-filter $i ; done fi else path=/opt/var/cache/malware-filter ipset -N malware-update hash:ip family inet hashsize 2048 maxelem 65536 for i in `cat $path/malware-filter.txt`; do ipset add malware-update $i ; done ipset swap malware-update malware-filter ipset destroy malware-update fi iptables-save | grep malware-filter > /dev/null 2>&1 || \ iptables -I FORWARD -m set $MATCH_SET malware-filter src,dst -j REJECT } run_ipset exit $?
/opt/var/cache/malware-filter/m 100%[========================================================>] 159.95K 187KB/s in 0.9s
/opt/var/cache/malware-filter/m [ <=> ] 2.34K --.-KB/s in 0s
/opt/var/cache/malware-filter/m [ <=> ] 10.51K 28.0KB/s in 0.4s
/opt/var/cache/malware-filter/m 100%[========================================================>] 17.00K 56.7KB/s in 0.3s
/opt/var/cache/malware-filter/m 100%[========================================================>] 283.41K 151KB/s in 1.9s
/opt/var/cache/malware-filter/m 100%[========================================================>] 6.61K 22.1KB/s in 0.3s
I now see IP addresses listed under Members: when running the ipset -L malware-filter command. I tried to ping six ip address from windows cmd line in the list and they all came back with request timed out. They are still can be pinged from SSH session.
THANK YOU! Great Job.