how to count IPs in use
David Forrest
drf at maplepark.com
Wed Oct 7 15:01:28 UTC 2009
On Wed, 7 Oct 2009, Peter Laws wrote:
> David W. Hankins wrote:
>
>> dhcpstatus is cool but when I'm in CLI, I often just "Control-R" and
>> find this in my bash history;
>>
>> awk '/^lease / { curlease = $2; } /^ binding state/ { lstates[curlease]
>> = $3; } END { for (curl in lstates) { tstates[lstates[curl]]++; } for (curs
>> in tstates) { print curs, tstates[curs]; } }' /var/db/dhcpd.leases
>>
>> It prints output like;
>>
>> active; 48
>> free; 81
>> backup; 158
>>
>> Which is useful to me as a spot-check.
>
>
> Very nice! One of my servers serves many networks and I'm really only
> concerned about one of them. Adding the first three octets of the IP address
> to "^lease " didn't seem to do the trick ... pointers?
>
> Other than to the O'Reilly sed and awk book, I mean. :-)
>
>
Peter, Add a match statement for the subnet like this:
awk '/^lease / { curlease = $2; } /^ binding state/ { match(curlease,
/192.168.102/) && lstates[curlease] = $3; } END { for (curl in lstates)
{tstates[lstates[curl]]++; } for (curs in tstates) { print curs,
tstates[curs]; } }' /var/db/dhcpd.leases
Dave
--
David Forrest
St. Louis, Missouri
More information about the dhcp-users
mailing list