2013-02-24 17:43:06 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
import pprint
|
|
|
|
import socket
|
|
|
|
|
|
|
|
from tornado import gen
|
|
|
|
from tornado.ioloop import IOLoop
|
|
|
|
from tornado.netutil import Resolver, ThreadedResolver
|
|
|
|
from tornado.options import parse_command_line, define, options
|
|
|
|
|
|
|
|
try:
|
|
|
|
import twisted
|
|
|
|
except ImportError:
|
|
|
|
twisted = None
|
|
|
|
|
|
|
|
try:
|
|
|
|
import pycares
|
|
|
|
except ImportError:
|
|
|
|
pycares = None
|
|
|
|
|
|
|
|
define('family', default='unspec',
|
|
|
|
help='Address family to query: unspec, inet, or inet6')
|
|
|
|
|
2013-03-02 23:58:02 +00:00
|
|
|
@gen.coroutine
|
2013-02-24 17:43:06 +00:00
|
|
|
def main():
|
|
|
|
args = parse_command_line()
|
|
|
|
|
|
|
|
if not args:
|
|
|
|
args = ['localhost', 'www.google.com',
|
|
|
|
'www.facebook.com', 'www.dropbox.com']
|
|
|
|
|
|
|
|
resolvers = [Resolver(), ThreadedResolver()]
|
|
|
|
|
|
|
|
if twisted is not None:
|
|
|
|
from tornado.platform.twisted import TwistedResolver
|
|
|
|
resolvers.append(TwistedResolver())
|
|
|
|
|
|
|
|
if pycares is not None:
|
|
|
|
from tornado.platform.caresresolver import CaresResolver
|
|
|
|
resolvers.append(CaresResolver())
|
|
|
|
|
|
|
|
family = {
|
|
|
|
'unspec': socket.AF_UNSPEC,
|
|
|
|
'inet': socket.AF_INET,
|
|
|
|
'inet6': socket.AF_INET6,
|
2017-12-31 18:44:42 +00:00
|
|
|
}[options.family]
|
2013-02-24 17:43:06 +00:00
|
|
|
|
|
|
|
for host in args:
|
|
|
|
print('Resolving %s' % host)
|
|
|
|
for resolver in resolvers:
|
2013-03-02 19:45:43 +00:00
|
|
|
addrinfo = yield resolver.resolve(host, 80, family)
|
2013-02-24 17:43:06 +00:00
|
|
|
print('%s: %s' % (resolver.__class__.__name__,
|
|
|
|
pprint.pformat(addrinfo)))
|
|
|
|
print()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2013-03-02 23:58:02 +00:00
|
|
|
IOLoop.instance().run_sync(main)
|