Skip to content

Instantly share code, notes, and snippets.

@kamawanu
Last active May 11, 2017 08:20
Show Gist options
  • Save kamawanu/146eecf38e50c6538a0a1e8fc701e2f9 to your computer and use it in GitHub Desktop.
Save kamawanu/146eecf38e50c6538a0a1e8fc701e2f9 to your computer and use it in GitHub Desktop.
{
gsub(/;$/,"",$0)
}
l != 0 && $1 != "set" {
d[$1] = $0
ll[$1] = $NF
if ( $1 == "client-hostname" ){
ll[$1] = $2 $3
}
}
l != 0 && ( /starts/ || /ends/ || /cltt/ || /tstp/ ) {
ll[$1] = d[$1] = $3 " " $4
}
l != 0 && ( /hardware/ ) {
ll[$1] = d[$1] = $NF
}
l != 0 && $1 == "set" {
d[$2] = $0
a = ""
for( ii = 4 ; ii<= NF ; ++ii ){
a = a " " $ii
}
ll[$2] = a
}
$1 == "lease" {
l = $2
for ( i in d ){d[i]="-"}
for ( i in ll ){ll[i]="-"}
d["NR"] = NR
d["tstp"] = "-------------------"
}
$0 == "}" {
if ( ll["binding"] == "free" ){
d["starts"] = "-------------------"
d["ends"] = "-------------------"
d["tstp"] = "-------------------"
d["cltt"] = "-------------------"
ll["hardware"] = "(" ll["hardware"] ")"
}
print l, d["starts"],d["ends"], d["cltt"], d["tstp"], ll["binding"], ll["hardware"], ll["client-hostname"], ll["vendor-class-identifier"], d["NR"]
catlog = ""
for( xx in ll ){
catlog = catlog " " xx "=" ll[xx]
}
print "#",l,catlog
l = 0
}
<?= filemtime("/var/lib/dhcp/dhcpd.leases") ?>
<PRE>
<?php
$f = popen("awk -f dhcpd.awk < /var/lib/dhcp/dhcpd.leases | sed -e \"/^#/d\" | sort -t. -k4 -n","r");
while( ($buf=fgets($f))!==false ){
echo htmlspecialchars($buf);
}
?>
</PRE>
#!/usr/bin/tclsh
proc lease {ip param} {
set param [ regsub -all = $param {} ]
set param [ regsub -all ";\n" $param "\n" ]
puts $param
eval $param
}
proc starts {c date time} {
upvar ip ip
}
proc ends {c date time} {
}
proc tstp {c date time} {
}
proc cltt {c date time} {
}
proc binding {date time} {
}
proc hardware {date time} {
}
proc uid {uid} {
}
proc client-hostname {hn} {
}
source /var/lib/dhcp/dhcpd.leases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment