source: trunk/pxeconfig/hexls @ 13

Last change on this file since 13 was 6, checked in by sscpbas, 22 years ago

Added the license info to each utility and fix and error in the getopt
handling for pxeconfig utility

File size: 1.5 KB
Line 
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'''
17hexls.py - Lists directory contents, but converts the hexadecimal IP numbers
18to dotted decimal notation (so you can at least see what you're doing..!!)
19
20Author: Walter de Jong <walter@sara.nl>
21Date:   January 2002
22
23CVS info
24  $Date: 2002/02/21 13:21:51 $
25  $Revision: 1.2 $
26'''
27
28import os
29import string
30import re
31
32def 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
49if __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
Note: See TracBrowser for help on using the repository browser.