#! /usr/bin/env python # Copyright (C) 2000, SARA. # # Permission to use, copy, modify, and distribute this software and its # documentation for non-commercial purposes and without fee is hereby # granted, provided that the above copyright notice appears in all copies # and that both the copyright notice and this permission notice appear in # supporting documentation. # # Neither SARA (Stichting Academisch Rekencentrum Amsterdam) nor the # nor the author make any representations about the suitability of this # software for any purpose. This software is provided ``as is'' without # express or implied warranty. # # ''' hexls.py - Lists directory contents, but converts the hexadecimal IP numbers to dotted decimal notation (so you can at least see what you're doing..!!) Author: Walter de Jong Date: January 2002 CVS info $Date: 2002/02/21 13:21:51 $ $Revision: 1.2 $ ''' import os import string import re def hexls(path): '''list directory, convert hexadecimal to dotted decimal''' regexp = re.compile('[' + string.hexdigits + ']+') for f in os.listdir(path): if regexp.match(f) and len(f) == 8: digit1 = string.atoi(f[:2], 16) digit2 = string.atoi(f[2:4], 16) digit3 = string.atoi(f[4:6], 16) digit4 = string.atoi(f[6:], 16) print '%s => %d.%d.%d.%d' % (f, digit1, digit2, digit3, digit4) else: if f[0] != '.': print f if __name__ == '__main__': import sys if len(sys.argv) > 1: for dir in sys.argv[1:]: hexls(dir) else: hexls('.') # EOB