Sorting by dhcp lease by time is it possible?

I have a few devices on my home network that are very "out of the way" .

Think a/v receiver buried in a cabinet. smart bulbs in extension ladder territory. and the like. So it is difficult, and time consuming to access the devices to read mac addresses, if they are even still visible.

I've tried looking up the mac addresses online to narrow the manufacturer down. But that has proven to be a snarf hunt many times.

They are showing as hostname unknown in pi dhcp. It would make identifying the devices much easier if they could be sorted either by the time the lease was given or by the length of the lease remaining.
Then i can document them in static assignments.

thanks in advance for any assistance.

I am not a dev on the project so can't verify my theory, but have a look at:

/etc/pihole/dhcp.leases

I believe the first column is a Unix timestamp, epoch seconds. I suspect that is the time the lease will expire, given inspection of the value relative to boot times of some of my machines.

Thanks,
I think that will work for me. I just performed a test and the device I just turned on appeared at the top of the file.

a few more steps than clicking a GUI. but so much better than risking life and limb on a ladder.

You might want to apply something like:

cat /etc/pihole/dhcp.leases | sort -r
or
sort -r /etc/pihole/dhcp.leases

That will sort the output in reverse order. I doubt the newest is always at the top of the file.

thanks again

1 Like