Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable reverse dns lookup in python webserver?

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 does a reverse dns lookup on every request for logging purposes onto the screen. there is no dns server available as i am running the server in a local network setting. so every reverse dns lookup leads to lookup timeout, delaying the server's response. how can i disable the dns lookup? i didn't find an answer in the python docs.

like image 983
alex Avatar asked Jul 20 '11 12:07

alex


People also ask

Why is reverse DNS needed?

Why is this so important? Reverse DNS is mainly used to track the origin of a website visitor, the origin of an e-mail message, etc. It is usually not as critical as the classic DNS, visitors will reach the website even without the presence of reverse DNS for the IP of the web server or the IP of the visitor.


1 Answers

You can subclass your own handler class, which won't do the DNS lookups. This follows from http://docs.python.org/library/cgihttpserver.html#module-CGIHTTPServer which says CGIHTTPRequestHandler is interface compatible with BaseHTTPRequestHandler and BaseHTTPRequestHandler has a method address_string().

class MyHandler(CGIHTTPServer.CGIHTTPRequestHandler):

    # Disable logging DNS lookups
    def address_string(self):
        return str(self.client_address[0])

handler = MyHandler
like image 120
Douglas Leeder Avatar answered Oct 22 '22 11:10

Douglas Leeder