Unifix knowledge database - The original one

Dashboard - News - Search - List - About - Admin


Parse dhcpd.leases and return all active leases

Author:mike - Sun Jun 3 18:52:48 2007

#!/usr/bin/php
<?
$fh=fopen("/chroot/dhcp/var/lib/dhcp/dhcpd.leases","r");

while ($dat=fgets($fh))
{
        if (preg_match("/lease/",$dat))
        {
                $active=false;
                $ip = preg_split("/ /",$dat);$ip=$ip[1];
                $dat=fgets($fh);
                while (!preg_match("/hardware ethernet/",$dat))
                {
                        if (preg_match("/binding state active/",$dat))
                        {
                                $active=true;
                        }
                        $dat=fgets($fh);
                }
                $mac = preg_split("/ |;/",$dat); $mac=$mac[4];
                if ($active)
                {
                        print $ip." - ".$mac."\n";
                }
        }
}
?>
Copyright(c) Unifix.org 2002-2011


Dashboard - News - Search - List - About - Admin
 
Powered by Mikjaer Consulting Solutions - Hosted by Specialhosting.dk