""" Daftar DHCP Client (c)2009 RAB Linux Indonesia """ import re import commands hosts = {} ip, mac, hostname = None, None, None f = open('/var/lib/dhcp3/dhcpd.leases','r') for line in f.readlines(): line = line.strip() match = re.compile('lease (.*) (.*)').search(line) if match: ip, mac, hostname = match.group(1), None, None continue match = re.compile('hardware ethernet (.*);').search(line) if match: mac = match.group(1) continue match = re.compile('client-hostname "(.*)";').search(line) if match: hostname = match.group(1) continue if ip and mac and hostname: hosts[ip] = {'mac': mac, 'name': hostname} ip, mac, hostname = None, None, None f.close() OK = {True: 'ON ', False: 'OFF'} for ip in hosts: connected = False for line in commands.getoutput('ping -c 3 %s' % ip).splitlines(): line = line.strip() match = re.compile(' (.*) received').search(line) if not match: continue connected = match.group(1) != '0' print OK[connected], ip.ljust(16), hosts[ip]['mac'].ljust(17), hosts[ip]['name']