Initial import to Tizen
[profile/ivi/python-twisted.git] / doc / names / examples / gethostbyname.py
1 #!/usr/bin/env python
2
3 # Copyright (c) Twisted Matrix Laboratories.
4 # See LICENSE for details.
5
6 """
7 Returns the IP address for a given hostname.
8 To run this script:
9 $ python gethostbyname.py <hostname>
10 e.g.:
11 $ python gethostbyname.py www.google.com
12 """
13 import sys
14 from twisted.names import client
15 from twisted.internet import reactor
16
17 def gotResult(result):
18     print result
19     reactor.stop()
20
21 def gotFailure(failure):
22     failure.printTraceback()
23     reactor.stop()
24
25 d = client.getHostByName(sys.argv[1])
26 d.addCallbacks(gotResult, gotFailure)
27
28 reactor.run()