feat: 适配 Fail2ban 0.10.2 版本 (#3503)

Refs #3490
pull/3504/head
ssongliu 2024-01-02 21:56:28 +08:00 committed by GitHub
parent b8a89d86a0
commit d626b2f4bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 3 deletions

View File

@ -93,12 +93,17 @@ func (f *Fail2ban) ReBanIPs(ips []string) error {
func (f *Fail2ban) ListBanned() ([]string, error) {
var lists []string
stdout, err := cmd.Exec("fail2ban-client get sshd banip")
stdout, err := cmd.Exec("fail2ban-client status sshd | grep 'Banned IP list:'")
if err != nil {
return lists, err
}
itemList := strings.Split(strings.ReplaceAll(stdout, "\n", ""), " ")
for _, item := range itemList {
itemList := strings.Split(strings.Trim(stdout, "\n"), "Banned IP list:")
if len(itemList) != 2 {
return lists, nil
}
ips := strings.Fields(itemList[1])
for _, item := range ips {
if len(item) != 0 {
lists = append(lists, item)
}