source: trunk/pxeconfig/hexls @ 62

Last change on this file since 62 was 62, checked in by bas, 18 years ago

hexls:

  • Use first element from gethostbyaddr

DEBIAN/control, Changelog:

  • Updated to new version 0.6.3
  • Property keywords set to Id
  • Property svn:keywords set to Id
File size: 1.8 KB
RevLine 
[3]1#! /usr/bin/env python
[14]2# Copyright (C) 2002
[6]3#
[14]4# This file is part of the pxeconfig utils
[6]5#
[14]6# This program is free software; you can redistribute it and/or modify it
7# under the terms of the GNU General Public License as published by the
8# Free Software Foundation; either version 2, or (at your option) any
9# later version.
[6]10#
[14]11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
[6]15#
[14]16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
19#
[3]20'''
21hexls.py - Lists directory contents, but converts the hexadecimal IP numbers
22to dotted decimal notation (so you can at least see what you're doing..!!)
23
24Author: Walter de Jong <walter@sara.nl>
25Date:   January 2002
26
[18]27Changes: Bas van der Vlies <basv@sara.nl>
28Date:    September 2002
29
[29]30SVN info
31  $Id: hexls 62 2005-11-22 11:22:18Z bas $
[3]32'''
33
34import os
35import string
36import re
[62]37import socket
[3]38
39def hexls(path):
40        '''list directory, convert hexadecimal to dotted decimal'''
41
[17]42        regexp = re.compile('[' + string.hexdigits + ']{8}' )
[3]43        for f in os.listdir(path):
44                if regexp.match(f) and len(f) == 8:
45                        digit1 = string.atoi(f[:2], 16)
46                        digit2 = string.atoi(f[2:4], 16)
47                        digit3 = string.atoi(f[4:6], 16)
48                        digit4 = string.atoi(f[6:], 16)
49
[61]50                        ipaddr = '%d.%d.%d.%d' % (digit1, digit2, digit3, digit4) 
51                        hostname = socket.gethostbyaddr(ipaddr)
52                        if hostname:
[62]53                                print '%s => %s => %s' % (f, ipaddr, hostname[0])
[61]54                        else:
55                                print '%s => %s' % (f, ipaddr)
[3]56                else:
57                        if f[0] != '.':
58                                print f
59
60
61if __name__ == '__main__':
62        import sys
63
64        if len(sys.argv) > 1:
65                for dir in sys.argv[1:]:
66                        hexls(dir)
67        else:
68                hexls('.')
69
70# EOB
71
Note: See TracBrowser for help on using the repository browser.