Initial import
[ldd.git] / resolve
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
20 import socket
21 import sys
22 import getopt
23 import time
24
25 from ldd import resolver
26
27 nameserver = (socket.AF_INET, "198.41.0.4", 53)
28 rtype = "a"
29 lrec = True
30 srec = False
31 verbose = False
32 opts, args = getopt.getopt(sys.argv[1:], "vrRs:t:p:")
33
34 for 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
51 if len(args) < 1:
52     print "No target given"
53     sys.exit(1)
54
55 res = resolver.resolver(nameserver, lrec, srec, verbose = verbose)
56 try:
57     rsp = res.squery(args[0], rtype)
58 except resolver.error, inst:
59     print "error: " + str(inst)
60 except KeyboardInterrupt:
61     sys.exit(1)
62 else:
63     print str(rsp)