summaryrefslogtreecommitdiff
path: root/doc/names/examples/gethostbyname.py
diff options
context:
space:
mode:
Diffstat (limited to 'doc/names/examples/gethostbyname.py')
-rwxr-xr-xdoc/names/examples/gethostbyname.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/doc/names/examples/gethostbyname.py b/doc/names/examples/gethostbyname.py
new file mode 100755
index 0000000..e10fd43
--- /dev/null
+++ b/doc/names/examples/gethostbyname.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+
+# Copyright (c) Twisted Matrix Laboratories.
+# See LICENSE for details.
+
+"""
+Returns the IP address for a given hostname.
+To run this script:
+$ python gethostbyname.py <hostname>
+e.g.:
+$ python gethostbyname.py www.google.com
+"""
+import sys
+from twisted.names import client
+from twisted.internet import reactor
+
+def gotResult(result):
+ print result
+ reactor.stop()
+
+def gotFailure(failure):
+ failure.printTraceback()
+ reactor.stop()
+
+d = client.getHostByName(sys.argv[1])
+d.addCallbacks(gotResult, gotFailure)
+
+reactor.run()