1 | #! /usr/bin/env python |
---|
2 | # Copyright (C) 2000, SARA. |
---|
3 | # |
---|
4 | # Permission to use, copy, modify, and distribute this software and its |
---|
5 | # documentation for non-commercial purposes and without fee is hereby |
---|
6 | # granted, provided that the above copyright notice appears in all copies |
---|
7 | # and that both the copyright notice and this permission notice appear in |
---|
8 | # supporting documentation. |
---|
9 | # |
---|
10 | # Neither SARA (Stichting Academisch Rekencentrum Amsterdam) nor the |
---|
11 | # nor the author make any representations about the suitability of this |
---|
12 | # software for any purpose. This software is provided ``as is'' without |
---|
13 | # express or implied warranty. |
---|
14 | # |
---|
15 | # |
---|
16 | ''' |
---|
17 | hexls.py - Lists directory contents, but converts the hexadecimal IP numbers |
---|
18 | to dotted decimal notation (so you can at least see what you're doing..!!) |
---|
19 | |
---|
20 | Author: Walter de Jong <walter@sara.nl> |
---|
21 | Date: January 2002 |
---|
22 | |
---|
23 | CVS info |
---|
24 | $Date: 2002/02/21 13:21:51 $ |
---|
25 | $Revision: 1.2 $ |
---|
26 | ''' |
---|
27 | |
---|
28 | import os |
---|
29 | import string |
---|
30 | import re |
---|
31 | |
---|
32 | def hexls(path): |
---|
33 | '''list directory, convert hexadecimal to dotted decimal''' |
---|
34 | |
---|
35 | regexp = re.compile('[' + string.hexdigits + ']+') |
---|
36 | for f in os.listdir(path): |
---|
37 | if regexp.match(f) and len(f) == 8: |
---|
38 | digit1 = string.atoi(f[:2], 16) |
---|
39 | digit2 = string.atoi(f[2:4], 16) |
---|
40 | digit3 = string.atoi(f[4:6], 16) |
---|
41 | digit4 = string.atoi(f[6:], 16) |
---|
42 | |
---|
43 | print '%s => %d.%d.%d.%d' % (f, digit1, digit2, digit3, digit4) |
---|
44 | else: |
---|
45 | if f[0] != '.': |
---|
46 | print f |
---|
47 | |
---|
48 | |
---|
49 | if __name__ == '__main__': |
---|
50 | import sys |
---|
51 | |
---|
52 | if len(sys.argv) > 1: |
---|
53 | for dir in sys.argv[1:]: |
---|
54 | hexls(dir) |
---|
55 | else: |
---|
56 | hexls('.') |
---|
57 | |
---|
58 | # EOB |
---|
59 | |
---|