Created
July 18, 2023 16:23
-
-
Save nhalstead/363b1220390e542e7502e5dab39c6a6d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from http.server import BaseHTTPRequestHandler, HTTPServer | |
class MyHTTPRequestHandler(BaseHTTPRequestHandler): | |
def _set_response(self, content_type='text/plain'): | |
self.send_response(200) | |
self.send_header('Content-type', content_type) | |
self.end_headers() | |
def do_GET(self): | |
self._set_response() | |
ip_address = self.client_address[0] # Get the client's IP address | |
self.wfile.write(ip_address.encode()) | |
def run(server_class=HTTPServer, handler_class=MyHTTPRequestHandler, port=8000): | |
server_address = ('', port) | |
httpd = server_class(server_address, handler_class) | |
print(f"Starting server on port {port}...") | |
httpd.serve_forever() | |
if __name__ == '__main__': | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment