Fail2ban is used to block users on certain patterns via reject
command.
Sometimes, especially when users are behind a NAT with a lot of users they get blocked unintendely. The user then writes an E-Mail and then I ask for his IP-Address to unblock (often E-Mail is forwarded to me, so I don't have the Mail header with his IP address).
To make this step easier, I'd like to redirect him to a special dynamic webpage that displays its IP-address and contact E-Mail. An example is here:
I'd like to have a similar webpage. An easy solution would be php, but that requires php to be installed and some webserver configuration. So simplest solution would be a small webserver that just serves a small text an IP address.
I've considered using python, because Python is already installed. I've found this article https://www.anycodings.com/1questions/2464569/how-do-i-get-the-client-ip-address-on-a-python-server but that prints the IP-Address only on stdout and serves files.
To use python as simple as with php it would require Flask or Django as far as I found out. However these are big frameworks and much oversized for this simple usecase. Also they probably can mean some security issue. This info page should also be secure by design so not creating any possible security issues compared to reject
method. I know DOS is more likely because of more data transmitted than using reject
, but size of this page is very small so this would be OK.
So what is an easy solution for this task? Python? If so could you hint some keywords I can search for to achieve this task? Are there other solutions? Maybe these fit even better than the python idea.
Found the solution here https://pythonbasics.org/webserver/
So basically you only need to add one line
self.wfile.write(bytes("<p>IP-Address: " + self.client_address[0] + "</p>", "utf-8"))
The client_address field is documented here https://docs.python.org/3/library/http.server.html#http.server.BaseHTTPRequestHandler.client_addressSo the full code for displaying the IP address of visitor is: