Searching dhcp.leases for an IP (by MAC)

Matthew Walker rorith at kydance.net
Tue Dec 12 09:27:25 MST 2006


Not sure if this will help you, but grep -B # will add # lines of context
before every match.

grep -B 5 "MAC" dhcpd.leases

should give you something you can use.

On Tue, December 12, 2006 9:20 am, Chris Carey wrote:
> I need to write a function to search dhcpd.leases file to find IP
> addresses (I have the corresponding MAC address). This would be easy
> for me if the file had each lease on one line. In that case I could
> just grep for the MAC address , then parse out the IP address.
> However, the IP address is 5 lines above the said MAC address:
>
> lease 10.10.32.209 {
>   starts 1 2006/12/11 19:04:32;
>   ends 2 2006/12/12 19:04:32;
>   binding state active;
>   next binding state free;
>   hardware ethernet 00:02:a1:1a:9c:94;
>   uid "\001\000\002\241\032\234\221";
> }
>
> I have some (pretty nasty) ideas of how to go about this but none of
> them are going to be very efficient.
>
> Ideas?
>
> /*
> PLUG: http://plug.org, #utah on irc.freenode.net
> Unsubscribe: http://plug.org/mailman/options/plug
> Don't fear the penguin.
> */
>


-- 
Matthew Walker
Kydance Hosting & Consulting
LAMP Specialist



More information about the PLUG mailing list