Skip to content

Instantly share code, notes, and snippets.

@kamermans
Created July 11, 2011 17:06
Star You must be signed in to star a gist
Save kamermans/1076290 to your computer and use it in GitHub Desktop.
Show status of all fail2ban jails at once
#!/bin/bash
JAILS=`fail2ban-client status | grep "Jail list" | sed -E 's/^[^:]+:[ \t]+//' | sed 's/,//g'`
for JAIL in $JAILS
do
fail2ban-client status $JAIL
done
@artfulrobot
Copy link

Thanks! can't believe there isn't a fail2ban-client status --all command!

@mattgorecki
Copy link

Excellent! It was -e for me on Centos 6.

@xrobin
Copy link

xrobin commented Jan 19, 2017

Great!
On a SLES box I had to use lowercase -e as well, and escape the + signs in the regex

JAILS=`fail2ban-client status | grep "Jail list" | sed -e 's/^[^:]\+:[ \t]\+//' | sed 's/,//g'`

@caic
Copy link

caic commented Jan 31, 2017

Thank you! It works on Ubuntu 16.04.

@acosonic
Copy link

Thank you! Also confirming works on Ubuntu 16.04

@maravedi
Copy link

maravedi commented Mar 8, 2017

This is perfect 👍

@ahmadawais
Copy link

@shlublu
Copy link

shlublu commented Jul 6, 2017

It has been said already, but many thanks (Ubuntu 16.04)! :)

@kofran
Copy link

kofran commented Aug 16, 2017

Thanks so much

@welrbraga
Copy link

Why make it easy if you can do hard? :-)

fail2ban-client status|awk -F: '/Jail list:/ { split($2,jail,",") ; for (i in jail) { gsub(/[\t ]/,"",jail[i]); system("fail2ban-client status "jail[i]); }; }'

@joergludwig
Copy link

Shorter version:
fail2ban-client status | sed -n 's/,//g;s/.*Jail list://p' | xargs -n1 fail2ban-client status

@Fieel
Copy link

Fieel commented Jan 17, 2018

Nice! Will use this script in my server, ty again <3

@VA2PE
Copy link

VA2PE commented Feb 9, 2018

Thanks, works well on CentOS 7.

@vkostyuk
Copy link

vkostyuk commented Aug 8, 2018

Nice. Needs sudo, so sudo sh -c "fail2ban-client status | sed -n 's/,//g;s/.*Jail list://p' | xargs -n1 fail2ban-client status"

@placecodex
Copy link

1# sudo apt-get remove fail2ban : remove the packet
2# sudo rm -rf fail2ban : delete fail2ban folder
3# re install again

@stefan1959
Copy link

doesn't ipset list do this?

@kamermans
Copy link
Author

@stefan1959 I don't know, although this post was over 5 years ago, so things have probably changed!

@kangarooo
Copy link

Thx

@Wepted
Copy link

Wepted commented Dec 21, 2020

thank you

@stueja
Copy link

stueja commented Feb 15, 2021

Thank you!

@deybin7
Copy link

deybin7 commented Mar 19, 2021

Thank you pal!

@jsagarino
Copy link

Thanks man!

@lls-hcr
Copy link

lls-hcr commented May 21, 2021

Very handy, thank you

@tmsBodnar
Copy link

thanks!

@Ravinou
Copy link

Ravinou commented Jan 14, 2022

Thanks !

@biesior
Copy link

biesior commented Sep 23, 2022

thx!

@Xuantung89
Copy link

Verify Github on Galxe. gid:hqaGx3KAt8heyLH9WYEKkm

@jmsfnch
Copy link

jmsfnch commented Oct 14, 2022

Ta very much!

@cchalifo999
Copy link

ty

@CDSoft
Copy link

CDSoft commented Dec 27, 2023

Thanks.

Since fail2ban banned lists all jails with their banned IP as a list of Python dictionaries, Python can also be used to get the list of jails:

$ fail2ban-client banned
[{'sshd': []}, {'apache-auth': []}, {'apache-badbots': []}, {'apache-noscript': ['AAA.BBB.CCC.DDD', 'AAA.BBB.CCC.DDD']}, {'apache-overflows': []}, {'apache-nohome': []}, {'apache-botsearch': []}, {'apache-fakegooglebot': []}, {'apache-modsecurity': []}, {'apache-shellshock': []}, {'php-url-fopen': []}, {'apache-pass': []}]
$ JAILS=$(python -c "print(' '.join(k for d in $(fail2ban-client banned) for k in d))")
$ echo $JAILS
sshd apache-auth apache-badbots apache-noscript apache-overflows apache-nohome apache-botsearch apache-fakegooglebot apache-modsecurity apache-shellshock php-url-fopen apache-pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment