example6-1.py revision 303975
1#!/usr/bin/python 2from unbound import ub_ctx,ub_strerror,RR_TYPE_A,RR_CLASS_IN 3 4ctx = ub_ctx() 5ctx.resolvconf("/etc/resolv.conf") 6 7status, result = ctx.resolve("test.record.xxx", RR_TYPE_A, RR_CLASS_IN) 8if status == 0 and result.havedata: 9 print "Result:", result.data.address_list 10else: 11 print "No record found" 12 13#define new local zone 14status = ctx.zone_add("xxx.","static") 15if (status != 0): print "Error zone_add:",status, ub_strerror(status) 16 17#add RR to the zone 18status = ctx.data_add("test.record.xxx. IN A 1.2.3.4") 19if (status != 0): print "Error data_add:",status, ub_strerror(status) 20 21#lookup for an A record 22status, result = ctx.resolve("test.record.xxx", RR_TYPE_A, RR_CLASS_IN) 23if status == 0 and result.havedata: 24 print "Result:", result.data.as_address_list() 25else: 26 print "No record found" 27 28