The question you are asking is a bit combersome, if you want to exclude duplicate ip adresses.
I am using Fail2ban on Ubuntu myself, so my examples is from my running server:
To find all active jails run the command: fail2ban-client status
.
On my server it will respond with the following output:
Status
|- Number of jail: 10
`- Jail list: dovecot, f2b-loop2, f2b-loop3, f2b-loop4, postfix, postfix-rbl, postfix-sasl, postfix-spam-ddos, pureftpd, sshd
In theory it is a bit trivial to create an array where each element in the array is the name of one of the jails.
In my own BASH shell script it is done with the following lines:
#!/bin/bash
JAILS=`fail2ban-client status | grep "Jail list" | sed -E 's/^[^:]+:[ \t]+//' | sed 's/,//g'`
for JAIL in $JAILS
do
# Insert the commands you want to run for each jail.
# The variable '$JAIL' contains the name of the jail.
#
# Like:
fail2ban-client get $JAIL banip --with-time
done
So first my script will get content from the jail 'dovecot', then 'f2b-loop2', then 'f2b-loop3' and so on.
However:
The same ip address might be featured in several jails. At least that is the case for my jails named f2b-loop(x) where (x) is a number from 2-4.
My loop jails is because I ban a particular ip for increasing amounts of time, like 2 hours, 1 day, 7 days and 1 month.
Therefore:
I have in the past fed my information into a binary search tree over ip adresses, so I could make summarized banning list if a suspicious amount of similar ip adresses was being blocked at the same time.
The reason is that creating 1 blocking rule that covers 64 ip addresses vs 64 individual rules is a bit more server friendly.
... and also the reason why I have more or less blocked 50% of all available ip adresses from 1 iranian, 2 russian and 2 chinese ISPs!
Anyhow:
From my initial snippet it is possible to all kinds of manipulation using shell scripting or piping output to a program that interacts with a database or whatever.
I would highly recommend you reading up on tutorials in shell scripting, if you have no experience with Linux in general, since that is one of the most powerfull tools you are going to use when working with Linux.