How to disable reverse dns search in python web server?

I have a simple python cgi server:

import BaseHTTPServer import CGIHTTPServer import cgitb; cgitb.enable() ## This line enables CGI error reporting server = BaseHTTPServer.HTTPServer handler = CGIHTTPServer.CGIHTTPRequestHandler server_address = ("", 8000) httpd = server(server_address, handler) httpd.serve_forever() 

the server performs a reverse DNS lookup for each on-screen logging request. there is no dns server since I start the server in the local network settings. therefore, each reverse dns search results in a search timeout, delaying the server response. how can i turn off dns search? I did not find the answer in python docs.

+6
source share
1 answer

You can subclass your own handler class that will not do DNS lookups. This follows from http://docs.python.org/library/cgihttpserver.html#module-CGIHTTPSERver , which states that the CGIHTTPRequestHandler interface is compatible with BaseHTTPRequestHandler and BaseHTTPRequestHandler has an address_string () method.

 class MyHandler(CGIHTTPServer.CGIHTTPRequestHandler): # Disable logging DNS lookups def address_string(self): return str(self.client_address[0]) handler = MyHandler 
+12
source

Source: https://habr.com/ru/post/893155/


All Articles