Initial import
[ldd.git] / resolve
... / ...
CommitLineData
1#!/usr/bin/python
2# ldd - DNS implementation in Python
3# Copyright (C) 2006 Fredrik Tolf <fredrik@dolda2000.com>
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19
20import socket
21import sys
22import getopt
23import time
24
25from ldd import resolver
26
27nameserver = (socket.AF_INET, "198.41.0.4", 53)
28rtype = "a"
29lrec = True
30srec = False
31verbose = False
32opts, args = getopt.getopt(sys.argv[1:], "vrRs:t:p:")
33
34for o, a in opts:
35 if o == "-s":
36 nameserver = (socket.AF_INET, a, 53)
37 if o == "-t":
38 if a == "any":
39 rtype = 255
40 else:
41 rtype = a
42 if o == "-p":
43 nameserver = nameserver[0:2] + (int(a),)
44 if o == "-r":
45 lrec = False
46 if o == "-R":
47 srec = True
48 if o == "-v":
49 verbose = True
50
51if len(args) < 1:
52 print "No target given"
53 sys.exit(1)
54
55res = resolver.resolver(nameserver, lrec, srec, verbose = verbose)
56try:
57 rsp = res.squery(args[0], rtype)
58except resolver.error, inst:
59 print "error: " + str(inst)
60except KeyboardInterrupt:
61 sys.exit(1)
62else:
63 print str(rsp)