3 # Copyright (c) Twisted Matrix Laboratories.
4 # See LICENSE for details.
7 Sample app to lookup SRV records in DNS.
9 $ python dns-service.py <service> <proto> <domain>
11 service = the symbolic name of the desired service.
12 proto = the transport protocol of the desired service; this is usually either TCP or UDP.
13 domain = the domain name for which this record is valid.
15 $ python dns-service.py sip udp yahoo.com
16 $ python dns-service.py xmpp-client tcp gmail.com
19 from twisted.names import client
20 from twisted.internet import reactor
23 def printAnswer((answers, auth, add)):
27 print '\n'.join([str(x.payload) for x in answers])
30 def printFailure(arg):
31 print "error: could not resolve:", arg
35 service, proto, domain = sys.argv[1:]
37 sys.stderr.write('%s: usage:\n' % sys.argv[0] +
38 ' %s SERVICE PROTO DOMAIN\n' % sys.argv[0])
41 resolver = client.Resolver('/etc/resolv.conf')
42 d = resolver.lookupService('_%s._%s.%s' % (service, proto, domain), [1])
43 d.addCallbacks(printAnswer, printFailure)