Created
September 21, 2017 12:49
-
-
Save ResolveWang/b441d8ac69f04e67613ef3c018ef1208 to your computer and use it in GitHub Desktop.
dnscache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# according to the blog:http://blog.csdn.net/Bone_ACE/article/details/55000101 | |
import socket | |
# from gevent import socket | |
_dnscache = {} | |
def _setDNSCache(): | |
""" DNS缓存 """ | |
def _getaddrinfo(*args, **kwargs): | |
if args in _dnscache: | |
# print str(args) + " in cache" | |
return _dnscache[args] | |
else: | |
# print str(args) + " not in cache" | |
_dnscache[args] = socket._getaddrinfo(*args, **kwargs) | |
return _dnscache[args] | |
if not hasattr(socket, '_getaddrinfo'): | |
socket._getaddrinfo = socket.getaddrinfo | |
socket.getaddrinfo = _getaddrinfo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment