zapret/ipset/create_ipset.sh

26 lines
463 B
Bash
Raw Normal View History

2016-02-15 16:34:45 +03:00
#!/bin/sh
# create ipset from resolved ip's
SCRIPT=$(readlink -f $0)
EXEDIR=$(dirname $SCRIPT)
. "$EXEDIR/def.sh"
TEMPIPSET=/tmp/ipset.$ZIPSET.tmp
ipset flush $ZIPSET || ipset create $ZIPSET hash:ip
for f in "$ZIPLIST" "$ZIPLIST_USER"
do
[ -f $TEMPIPSET ] && rm -f $TEMPIPSET
[ -n "$f" ] && {
echo Adding $f
sort $f | uniq | while read ip;
do
echo add $ZIPSET $ip >>$TEMPIPSET
done
ipset -! restore <$TEMPIPSET 2>&1
rm -f $TEMPIPSET
}
done