diff --git a/doc/THANKS b/doc/THANKS index f054be22e..63ef20bbd 100644 --- a/doc/THANKS +++ b/doc/THANKS @@ -334,6 +334,7 @@ Andres Riancho for reporting a bug and suggesting some features for including sqlmap in his great web application audit and attack framework, w3af, http://w3af.sourceforge.net + for suggesting a way for handling DNS caching Antonio Riva for reporting a bug when running with python 2.5 @@ -367,6 +368,9 @@ Sven Schluter for providing with a patch for waiting a number of seconds between each HTTP request +Ryan Sears + for suggesting an enhancement + Uemit Seren for reporting a minor adjustment when running with python 2.6 diff --git a/lib/core/option.py b/lib/core/option.py index a490e5e90..3e36991db 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -759,6 +759,22 @@ def __setThreads(): if not isinstance(conf.threads, int) or conf.threads <= 0: conf.threads = 1 +def __setDNSCache(): + """ + Makes a cached version of socket._getaddrinfo to avoid subsequent DNS requests. + """ + + def _getaddrinfo(*args, **kwargs): + if args in kb.cache: + return kb.cache[args] + else: + kb.cache[args] = socket._getaddrinfo(*args, **kwargs) + return kb.cache[args] + + if socket.getaddrinfo != _getaddrinfo: + socket._getaddrinfo = socket.getaddrinfo + socket.getaddrinfo = _getaddrinfo + def __setHTTPProxy(): """ Check and set the HTTP proxy to pass by all HTTP requests. @@ -1553,6 +1569,7 @@ def init(inputOptions=advancedDict(), overrideOptions=False): __setHTTPMethod() __setHTTPAuthentication() __setHTTPProxy() + __setDNSCache() __setSafeUrl() __setGoogleDorking() __urllib2Opener()