Hi,
I am trying to parse some dhcp-lease files to extract the ip, mac and
hostname.
I am struggling to get either, the regex of the $/, correct. I am not
sure which combination of these I should use.
There is some sample data and my best effort below. Can anyone offer
any pointers?
TIA,
Dp.
======= Sample Data =========
...
lease 196.222.237.209 {
starts 5 2007/02/23 17:53:57;
ends 6 2007/02/24 17:53:57;
binding state active;
next binding state free;
hardware ethernet 00:60:04:28:28:01;
client-hostname "lab.mydomain.com";
}
lease 196.222.237.209 {
starts 5 2007/02/23 17:53:57;
ends 6 2007/02/24 17:53:57;
binding state active;
next binding state free;
hardware ethernet 00:60:04:38:38:01;
client-hostname "lab.mydomain.com";
}
lease 196.222.237.195 {
starts 5 2007/02/23 17:54:04;
ends 6 2007/02/24 17:54:04;
binding state active;
next binding state free;
hardware ethernet 00:0c:c1:33:31:0d;
uid "\001\000\014\361\3231\015";
client-hostname "puck";
}
=============================
============== My effort ===========
#!/usr/bin/perl
use strict;
use warnings;
my $file = '/var/lib/dhcp3/dhcpd.leases';
my ($ip,$mac,$host);
#$/ = "}\n";
$/ = '';
open(FH,$file) or die "Can't open $file: $!\n";
while (<FH>) {
chomp;
($ip,$mac,$host) = ($_ =~
/lease\s+(\d{3}\.\d{3}\.\d{3}\.\d+).*thernet\s+(\d{2}:\d{2}:\d{2}:\d{2
}:\d{2}:\d{2}).*ostname\s+\
"(\w+\.scien.*)"/smg);
print "$ip $mac $host\n";
}
=======================
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/