Before 0.11, there was no default feature or a setting within fail2ban to achieve this. But starting with the upcoming 0.11 release, ban time is automatically calculated and increases exponentially with each new offense which, on the long term, will mean a more or less permanent block.
Until then, your best approach is probably setting up fail2ban to monitor its own log file. It is a two step process...
Step 1
We could need to create a filter to check for BAN's in the log file (fail2ban's log file)
Step 2
We need to define the jail, similar to the following...
[fail2ban]
enabled = true
filter = fail2ban
action = iptables-allports[name=fail2ban]
logpath = /path/to/fail2ban.log
# findtime: 1 day
findtime = 86400
# bantime: 1 year
bantime = 31536000
Technically, it is not a permanent block, but only blocks for a year (that we can increase too).
Anyway, for your question (Can this be achieved with fail2ban alone or I need to write my own script to do that?)... writing own script might work well. Setting up the script to extract the frequently banned IPs and then putting them into /etc/hosts.deny
is what I'd recommend.