PID COMMAND %CPU TIME #TH #PRTS #MREGS RPRVT RSHRD RSIZE VSIZE 1279 perl 19.6% 0:02.28 1 10 21 524K 1.42M 1.62M 2.92M #### PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND 16974 root 25 0 1696 1696 1128 R 51.5 0.1 0:02 ip_update.pl #### #!/usr/bin/perl use strict; ##################################################### # Update MAC-IP pairings for all registered devices # ##################################################### my %devices; # Open dhcpd.conf and initialize the %devices hash with all # registered modems and cpes open (DHCPDCONF, "dhcpd.conf") or die "Cannot read from file: $!"; while () { $devices{lc($1)} = '000.000.000.000' if (/#.*#.*#.*# Modem MAC: (\w+:\w+:\w+:\w+:\w+:\w+)/ or /subclass ".*" 1:(\w+:\w+:\w+:\w+:\w+:\w+)/); } close DHCPDCONF; # open leases file and match mac addresses in %devices with active ips open (LEASES, "dhcpd.leases"); my ($current_ip, $state); while () { $current_ip = $1 and next if /^\s*lease (\d+.\d+.\d+.\d+)/; $state = $1 and next if /^\s*binding state (\w+)/; $devices{lc($1)} = $current_ip and print lc($1) . " - " . $devices{lc($1)} . "\n" and next if (/^\s*hardware ethernet (\w+:\w+:\w+:\w+:\w+:\w+)/ and $state eq 'active' and exists $devices{lc($1)}); } close LEASES; # substitute old ip with current value open (DHCPDCONF, "dhcpd.conf") or die "Cannot read from file: $!"; open (DHCPDCONFNEW, ">dhcpd.conf.new") or die "Cannot create file: $!"; while( ) { my $device = lc($1) if /#.*#.*#.*# Modem MAC: (\w+:\w+:\w+:\w+:\w+:\w+)/; s/(#.*#.*# Modem IP: ).*( # Modem MAC: $device)/$1$devices{$device}$2/i; print DHCPDCONFNEW; } close DHCPDCONF; close DHCPDCONFNEW; system("cp dhcpd.conf.new dhcpd.conf"); ######## Update LDAP database # not implemented yet.