how to count IPs in use
John Hascall
john at iastate.edu
Wed Oct 7 15:14:39 UTC 2009
> 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
If only there were a way to file away these sorts of shell scripts.... :)
> 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?
The main problem with that is the /^ binding state/ pattern
will still match leases you don't care about. The other is
you may have forgotten that '.' is match-any-char in a
regular expression.
So, maybe something like:
awk '/^lease / {OK=0} /^lease 192\.168\.1\./ { OK=1; curlease = $2; } /^ binding state/ { if (OK) lstates[curlease] = $3; } END { for (curl in lstates) { tstates[lstates[curl]]++; } for (curs in tstates) { print curs, tstates[curs]; } }' /var/db/dhcpd.leases
John
More information about the dhcp-users
mailing list