Parse dhcpd.leases and return all active leases

#!/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";
                }
        }
}
?>
Dette indlæg blev udgivet i Apache, Knowledge Base, Old Base, PHP. Bogmærk permalinket.

Skriv et svar