/usr/share/doc/python-getdns-doc/examples/get-srv.py is in python-getdns-doc 0.6.0-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #!/usr/bin/env python
#
"""
Lookup an SRV record and printout all the SRV priority, weight, targets,
and associated IP addresses of the targets.
"""
import getdns, pprint, sys, time
srvname = sys.argv[1]
ctx = getdns.Context()
try:
results = ctx.service(name=srvname)
except getdns.error as e:
print(str(e))
sys.exit(1)
if results.status == getdns.RESPSTATUS_GOOD:
for reply in results.replies_tree:
for a in reply["answer"]:
rrname = a["name"]
rrtype = a["type"]
if rrtype == getdns.RRTYPE_SRV:
rdata = a["rdata"]
prio, weight, port, target = rdata['priority'], rdata['weight'], rdata['port'], rdata['target']
print("SRV {0} --> {1} {2} {3} {4}".format(rrname, prio, weight, port, target))
else:
print("getdns.service() returned an error: {0}".format(results.status))
|