mx-lookup.py revision 285206
150472Speter#!/usr/bin/python 233975Sjdp# vim:fileencoding=utf-8 374313Sobrien''' 474313Sobrien mx-lookup.py: Lookup for MX records 574313Sobrien 674313Sobrien Authors: Zdenek Vasicek (vasicek AT fit.vutbr.cz) 733975Sjdp Marek Vavrusa (xvavru00 AT stud.fit.vutbr.cz) 868675Sobrien 998623Sobrien Copyright (c) 2008. All rights reserved. 1033975Sjdp 1184951Sobrien This software is open source. 1285193Sobrien 1384951Sobrien Redistribution and use in source and binary forms, with or without 1446328Sdfr modification, are permitted provided that the following conditions 1546291Sdfr are met: 1646291Sdfr 1733975Sjdp Redistributions of source code must retain the above copyright notice, 18 this list of conditions and the following disclaimer. 19 20 Redistributions in binary form must reproduce the above copyright notice, 21 this list of conditions and the following disclaimer in the documentation 22 and/or other materials provided with the distribution. 23 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 26 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE 28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 POSSIBILITY OF SUCH DAMAGE. 35''' 36import unbound 37 38ctx = unbound.ub_ctx() 39ctx.resolvconf("/etc/resolv.conf") 40 41status, result = ctx.resolve("nic.cz", unbound.RR_TYPE_MX, unbound.RR_CLASS_IN) 42if status == 0 and result.havedata: 43 print("Result:") 44 print(" raw data:", result.data) 45 for k in result.data.mx_list: 46 print(" priority:%d address:%s" % k) 47 48status, result = ctx.resolve("nic.cz", unbound.RR_TYPE_A, unbound.RR_CLASS_IN) 49if status == 0 and result.havedata: 50 print("Result:") 51 print(" raw data:", result.data) 52 for k in result.data.address_list: 53 print(" address:%s" % k) 54