[admin@comm perl]$ ls -l dh*
-rw-r--r-- 1 admin wheel 193 Окт 8 12:50 dhcpd.conf
-rwxr-xr-x 1 admin wheel 576 Окт 8 12:46 dhcp_parse
[admin@comm perl]$
[admin@comm perl]$ cat ./dhcpd.conf
host 192.168.1.98 {
hardware ethernet 00:50:22:b0:39:c7;
fixed-address 192.168.1.98;
}
host 192.168.1.99 {
fixed-address 192.168.1.99;hardware ethernet 00:50:02:e0:00:17;
}[admin@comm perl]$ ./dhcp_parse
192.168.1.98 00:50:22:b0:39:c7 192.168.1.98
192.168.1.99 00:50:02:e0:00:17 192.168.1.99
[admin@comm perl]$
[admin@comm perl]$ cat ./dhcp_parse
#!/usr/bin/perl
use strict;
use warnings;
use vars qw( $config %hosts );
sub parse_host_record($$);
undef $/;
open(F, '<', 'dhcpd.conf') or die($!);
$config = <F>;
close( F );
parse_host_record( $1, $2 ) while $config =~ /\b host \s+ (\S+) \s* { ([^}]+) } /gsix;
foreach my $key ( sort keys %hosts ) {
printf( "%s %s %s\n", $key, $hosts{$key}{'hardware ethernet'}, $hosts{$key}{'fixed-address'} );
}
sub parse_host_record($$) {
my( $host, $params );
( $host, $params ) = @_;
$hosts{$host}{$1} = $2 while $params =~ / \s* (.+?) \s+ (\S+) \s* ; /gsix;
}