implemented DNS caching mechanism

This commit is contained in:
Miroslav Stampar 2011-04-07 21:39:18 +00:00
parent ae4ea0af45
commit b288e5ef57
2 changed files with 21 additions and 0 deletions

View File

@ -334,6 +334,7 @@ Andres Riancho <andres.riancho@gmail.com>
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 <antonio.riva@gmail.com>
for reporting a bug when running with python 2.5
@ -367,6 +368,9 @@ Sven Schluter <sschlueter@netzwerk.cc>
for providing with a patch for waiting a number of seconds between
each HTTP request
Ryan Sears <rdsears@mtu.edu>
for suggesting an enhancement
Uemit Seren <uemit.seren@gmail.com>
for reporting a minor adjustment when running with python 2.6

View File

@ -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()