#!/usr/bin/env python3 """ HTTP Input Server - Serves IPs one per request from a list Usage: python3 http_input_server.py """ from http.server import HTTPServer, BaseHTTPRequestHandler import itertools import signal import sys # List of IPs to serve (rotates through them) IPS = [ "8.8.8.8", "1.1.1.1", "208.67.222.222", "9.9.9.9", "8.8.4.4" ] ip_cycle = itertools.cycle(IPS) class InputHandler(BaseHTTPRequestHandler): def do_GET(self): ip = next(ip_cycle) print(f"[INPUT] Serving IP: {ip}") self.send_response(200) self.send_header('Content-Type', 'text/plain') self.end_headers() self.wfile.write(f"{ip}\n".encode()) def log_message(self, format, *args): # Suppress default logging pass def signal_handler(sig, frame): print("\n\nšŸ›‘ Shutting down gracefully...") sys.exit(0) if __name__ == "__main__": PORT = 8080 # Register signal handlers for graceful shutdown signal.signal(signal.SIGINT, signal_handler) # Ctrl+C signal.signal(signal.SIGTERM, signal_handler) # kill command server = HTTPServer(('0.0.0.0', PORT), InputHandler) print(f"🌐 HTTP Input Server running on http://localhost:{PORT}") print(f" Serving IPs in rotation: {IPS}") print(f" Press Ctrl+C to stop") try: server.serve_forever() except KeyboardInterrupt: pass finally: server.server_close() print("\nāœ… Server stopped cleanly")