Python regex for denyhosts – Stack Overflow

I need a regex string to give to denyhosts config for filtering invalid ssh login attempts to my remote server.

Here is the regex that i am using currently:

USERDEF_FAILED_ENTRY_REGEX=.*sshd.* Connection closed by .* (?P<host>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) port \d{1,5} \[preauth\]

It filters this kind of logs perfectly:

sshd[4086]: Connection closed by authenticating user root 141.98.10.172 port 50610 [preauth]

and gets 141.98.10.172 within text.

However i need to filter below ones too in same regex:

sshd[4260]: Disconnected from authenticating user root 128.199.82.240 port 46392 [preauth]
sshd[4262]: Invalid user admin12 from 43.134.178.78 port 36540

how can i do this in one simple regex?

Read more here: Source link