1 #!/usr/bin/env python2.7
2 # Copyright 2015 gRPC authors.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 """Makes DNS queries for A records to specified servers"""
20 import twisted.internet.task as task
21 import twisted.names.client as client
22 import twisted.internet.reactor as reactor
26 argp = argparse.ArgumentParser(description='Make DNS queries for A records')
27 argp.add_argument('-s',
31 help='Host for DNS server to listen on for TCP and UDP.')
32 argp.add_argument('-p',
36 help='Port that the DNS server is listening on.')
37 argp.add_argument('-n',
41 help=('Name of the record to query for. '))
42 argp.add_argument('-t',
46 help=('Force process exit after this number of seconds.'))
47 args = argp.parse_args()
49 def OnResolverResultAvailable(result):
50 answers, authority, additional = result
54 def BeginQuery(reactor, qname):
55 servers = [(args.server_host, args.server_port)]
56 resolver = client.Resolver(servers=servers)
57 deferred_result = resolver.lookupAddress(args.qname)
58 deferred_result.addCallback(OnResolverResultAvailable)
59 return deferred_result
61 task.react(BeginQuery, [args.qname])
64 if __name__ == '__main__':