The script for adding IP addresses from a file to ipset

It took one day to write a script to add to ipset all the IP for which the session was started on the access server, Abills billing was used, so I decided to take IP addresses from the MySQL billing table.

The first step is to create a test ipset:

ipset create test iphash

Create a script file:

nano iplist.sh

Add the following content to it:

mysql -u root -e "SELECT INET_NTOA(framed_ip_address) FROM abills.internet_online WHERE (status=1 or status>=3) AND guest=0;" -s -N > iplist.txt
iplist_data=$(cat iplist.txt)
for row_data in $iplist_data; do ipset -exist add test ${row_data}; done
rm iplist.txt

We execute the script and check:

chmod +x iplist.sh
./iplist.sh
ipset list test | wc -l
ipset -L

See also my article – Ip-up and ip-down scripts with ipset for Accel-ppp

Leave a comment

Leave a Reply