Hello all,
I have found a very useful little module for parsing DHCP logs and in the following script I have been able to create a hash of hashes based on the data extracted from a dhcp log. However, my problem now is that I want to determine what subnet a host is on. For the moment I will only be dealing with /25 subnets meaning hosts with a final octet greater than 128 or less than 128. In my code below I tried to split the variable $dhcp{$hostname}->{ip} into 4 separate octets but that failed, I then tried to match the last 1 to 3 characters in $dhcp{$hostname}->{ip} but that also failed. Can anyone tell me how I might do this? I have included a short sample of the dhcp log I am parsing with this script. #!/usr/bin/perl use strict; use warnings; system "clear"; use Text::DHCPparse; my $return; my %dhcp; $return = leaseparse('dhcpd.leases'); foreach (keys %$return) { ($ip, $time, $mac, $name) = unpack("A17 A21 A19 A30", $return->{$_}); $dhcp{$name} = {ip => $ip, mac => $mac}; } print "Enter hostname: \n"; chomp(my $hostname = <STDIN>); print "I found $hostname with ip addr $dhcp{$hostname}->{ip}\n"; #my($oct1, $oct2, $oct3, $oct4) = split (/./, $dhcp{$hostname}->{ip}); my ($range)=$dhcp{$hostname}->{ip}; #=~(/\d{1,3}$/); my ($range_type)=$range=~(/\d{1,3}$/); print "$range_type\n"; print "$dhcp{$hostname}->{ip}\n"; *******DHCP log data example******* lease 10.10.97.207 { starts 2 2005/12/20 16:10:51; ends 2 2005/12/20 20:10:51; tstp 2 2005/12/20 20:10:51; binding state free; hardware ethernet 00:0b:97:2b:ea:fe; uid "\001\000\013\227+\352\376"; client-hostname "HOST1"; }