Schreiben Sie einen einfachen Python3 HTTPS-Dateiserver, der auf eine Verbindung von einem Client wartet und sobald er eine Verbindung erhält, erlaubt nur weitere Verbindungen von dieser einzelnen Verbindungs-IP-Adresse. Erwidern Sie den Server mit einer Fehlerseite, wenn ein anderer Benutzer versucht, sich zu verbinden.
Here is a simple HTTPS file server in Python 3 that implements the requirements you specified:

import http.server
import socketserver
import ssl

HOSTNAME = "0.0.0.0"
PORT = 8000
CERT_FILE = "server.pem"
KEY_FILE = "key.pem"
ALLOWED_CLIENT_IP = None

class CustomHandler(http.server.SimpleHTTPRequestHandler):
    def do_GET(self):
        if ALLOWED_CLIENT_IP and self.client_address[0] != ALLOWED_CLIENT_IP:
            self.send_error(403, "Forbidden", "You are not authorized to access this resource")
            return
        
        if self.path.endswith("/download"):
            ALLOWED_CLIENT_IP = self.client_address[0]
            super().do_GET()
        else:
            self.send_error(404, "Not Found", "The requested resource was not found on this server.")

with socketserver.TCPServer((HOSTNAME, PORT), CustomHandler) as httpd:
    httpd.socket = ssl.wrap_socket(httpd.socket, certfile=CERT_FILE, keyfile=KEY_FILE, server_side=True)
    print(f"Serving HTTPS on {HOSTNAME}:{PORT}")
    httpd.serve_forever()


In this code, we create a custom HTTP request handler CustomHandler that extends http.server.SimpleHTTPRequestHandler and overrides the do_GET method. This method checks if the incoming request is from an allowed client IP address (stored in ALLOWED_CLIENT_IP). If the incoming request is from a different IP address, it sends a "Forbidden" error.

If the request is from an allowed IP address, the code checks if the requested resource is the download endpoint. If it is, it updates ALLOWED_CLIENT_IP to the incoming IP address and calls the parent implementation of do_GET. This will serve the requested file once to the connecting IP address.

If the requested resource is not the download endpoint, the code sends a "Not Found" error.

The server uses SSL for secure communication, so you will need to generate your own SSL certificate and key. The certificate and key files should be stored in the same directory as the script and their filenames should be specified in the CERT_FILE and KEY_FILE variables, respectively.