~justin-fathomdb/nova/justinsb-openstack-api-volumes

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/doc/names/examples/dns-service.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# Copyright (c) 2009 Twisted Matrix Laboratories.
 
4
# See LICENSE for details.
 
5
 
 
6
"""
 
7
Sample app to lookup SRV records in DNS.
 
8
"""
 
9
 
 
10
from twisted.names import client
 
11
from twisted.internet import reactor
 
12
import sys
 
13
 
 
14
def printAnswer((answers, auth, add)):
 
15
    if not len(answers):
 
16
        print 'No answers'
 
17
    else:
 
18
        print '\n'.join([str(x.payload) for x in answers])
 
19
    reactor.stop()
 
20
 
 
21
def printFailure(arg):
 
22
    print "error: could not resolve:", arg
 
23
    reactor.stop()
 
24
 
 
25
try:
 
26
    service, proto, domain = sys.argv[1:]
 
27
except ValueError:
 
28
    sys.stderr.write('%s: usage:\n' % sys.argv[0] +
 
29
                     '  %s SERVICE PROTO DOMAIN\n' % sys.argv[0])
 
30
    sys.exit(1)
 
31
 
 
32
resolver = client.Resolver('/etc/resolv.conf')
 
33
d = resolver.lookupService('_%s._%s.%s' % (service, proto, domain), [1])
 
34
d.addCallbacks(printAnswer, printFailure)
 
35
 
 
36
reactor.run()