#! /usr/bin/env python ''' 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/19 09:38:10 $ $Revision: 1.1 $ ''' 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