Skip to content

Instantly share code, notes, and snippets.

@ResolveWang
Created September 21, 2017 12:49
Show Gist options
  • Save ResolveWang/b441d8ac69f04e67613ef3c018ef1208 to your computer and use it in GitHub Desktop.
Save ResolveWang/b441d8ac69f04e67613ef3c018ef1208 to your computer and use it in GitHub Desktop.
dnscache
# 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