Hi all, I am trying to write a script that will regularly pull information from a Windows XP system, store it in a database (DBM::Deep), and if requeried, report the changes and update the database.
However, the test code I have below has two behaviors that I do not understand: 1) If I assign an array reference (containing hashes itself) as a hash value to the DBM::Deep database, the original array seems to point to the database instead of it's original values. I'm not sure why it does this, but it seems to cause issue 2. 2) If I use Data::Compare to compare a data structure with the same data structure stored in the DBM::Deep database, the compare returns false, even though the elements, keys, and values are all identical. #1 would not matter if it didn't cause problem #2. Any way I can avoid the failed comparison? Thanks for any assistance provided. Regards, Roman ----------------------------------------------------------------- #!/perl/bin/perl use strict; use warnings; use Data::Compare; use DBM::Deep; use Net::NBName; use Win32API::Net; my $database = &OpenDB("test.db"); my $ip = '10.0.0.1'; my @old_info; my @new_info = &QueryHost($ip); my @control = @new_info; print("[EMAIL PROTECTED] = @control\n\n"); print("[EMAIL PROTECTED] = @new_info\n\n"); my $match = 9; $match = Compare([EMAIL PROTECTED], [EMAIL PROTECTED]); print("[EMAIL PROTECTED] and [EMAIL PROTECTED] matches?: $match\n\n\n"); $database->{$ip} = [EMAIL PROTECTED]; if ($database->exists($ip)) { @old_info = @{ $database->{$ip} }; } print("[EMAIL PROTECTED] = @old_info\n\n"); print("[EMAIL PROTECTED] = @control\n\n"); print("[EMAIL PROTECTED] = @new_info\n\n"); $match = 9; $match = Compare([EMAIL PROTECTED], [EMAIL PROTECTED]); print("[EMAIL PROTECTED] and [EMAIL PROTECTED] matches?: $match\n"); $match = Compare([EMAIL PROTECTED], [EMAIL PROTECTED]); print("[EMAIL PROTECTED] and [EMAIL PROTECTED] matches?: $match\n"); sub OpenDB { # Argument(s): A string containing the database filename to be used. # Returned: A scalar reference holding the database object. my ($filename) = @_; my $db = DBM::Deep->new( file => $filename, locking => 1, autoflush => 1 ); # Test: see if removing this increases speed return($db); } sub QueryHost { # Argument(s): IP Address (string) # Returned: MAC Address (string), Host name (string) and User information (hash) my ($ip) = @_; my $netBiosObject = Net::NBName->new(); my $netBiosStatus = $netBiosObject->node_status($ip); my ($domain, $user, $machine) = ("Unknown", "Unknown", "Unknown"); my ($mac, %usersHash); my $upFlag = 0; my @arp = `arp -a $ip`; # Windows-only command due to lack of # ARP packet generation capability. # For using this on *nix, you need to # change this statement. if (defined($arp[3])) { $arp[3] =~ m/\s+\S+\s+(\S+)\s+/; $mac = $1; } if ($netBiosStatus) # Conducts a NetBIOS check for Windows-type machines { # modified code from NBName example on CPAN ((c)James Macfarlane) for my $rr ($netBiosStatus->names) { if ($rr->suffix == 0 && $rr->G eq "GROUP") { $domain = $rr->name; } if ($rr->suffix == 3 && $rr->G eq "UNIQUE") { $user = $rr->name; } if ($rr->suffix == 0 && $rr->G eq "UNIQUE") { $machine = $rr->name unless $rr->name =~ /^IS~/; } } $mac = $netBiosStatus->mac_address unless $mac; # end modified code ((c)James Macfarlane) %usersHash = QueryUsers($machine); } $mac = '00-00-00-00-00-00' unless $mac; $mac =~ tr/[a-z]/[A-Z]/; # Ensure all MACs are uppercase to ease comparing return ($mac, $machine, %usersHash); } sub QueryUsers { my ($system) = @_; my (%usersEnumerated, @usersList); my $filter = 0; my $level = 3; Win32API::Net::UserEnum($system, [EMAIL PROTECTED], $filter); foreach my $user (@usersList) { my %tempHash; Win32API::Net::UserGetInfo($system, $user, $level, \%tempHash); $usersEnumerated{$user} = \%tempHash; } return(%usersEnumerated); } ----------------------------------------------------------------- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/