zapret/ipset/create_ipset.sh

26 lines
463 B
Bash
Raw Normal View History

2016-02-15 13:34:45 +00: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