Answer the question
In order to leave comments, you need to log in
Track an event when connecting to a port in Linux?
Prompt how it is possible to execute something at event of connection to the server.
For example, there is port 21 (this is an example, I don’t need to advise you to do something with FTP), how to systemically get the client’s ip when it connects, check it in the spam database and block it if necessary
(this is also an example, the execution can be anything ).
Can you tell me at least superficially the scheme for implementing this?
Maybe there are already ready-made solutions and programs for Linux?
Answer the question
In order to leave comments, you need to log in
There is a standard package, fail2ban.
It parses the application logs (in this case, ftp), and, in accordance with the jail settings, automatically blocks when the ip address is suspiciously active.
1. Refine the program :)
2. Parse the logs into which the program displays connection data
There is no general technique here and cannot be. A client connection to a port is a standard event for the server and is handled however they like. And the format of the logs is generally arbitrary. See fail2ban - it's already been suggested.
sudo iptables -I INPUT -p udp --dport 21 -d a.b.c.d -j LOG --log-prefix="TRIGGER_ME_NOW"
tail -f /var/log/firewall.log | awk '/TRIGGER_ME_NOW/ {system("/usr/local/bin/script.sh")}'
Shouldn't the FTP server do this, not Linux? In the same Filezilla there is an excellent IP FIlter
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question