In the following subroutine there must be a better way to find a remote NT
machine's domain. It spawns NBTSTAT and parses the output, but I don't
feel comfortable with that.
print " $machine is in domain ", NTDomain( $machine ), "\n";
sub NTDomain {
my $machine = shift || Win32::NodeName();
# Remove back-slashes
$machine =~ s/\\//g;
# If the machine was already here,
# the domain was cached in %Domain
if ( defined $Domain{ $machine } ){
return $Domain{ $machine };
}
# If it's the local machine, use Win32::
if ( uc $machine eq uc Win32::NodeName() ){
$Domain{$machine} = Win32::DomainName();
}
# use NBTSTAT to get remote machine's domain
# (this part I don't like)
if ( not defined $Domain{ $machine } ){
for ( `$ENV{SYSTEMROOT}\\SYSTEM32\\NBTSTAT.EXE -a $machine` ){
$Domain{ $machine } = $1 if /(\S+)\s+<00>\s+GROUP/i;
}
}
if ( not defined $Domain{ $machine } ){
warn "UNABLE TO GET DOMAIN WITH NBTSTAT.EXE.\n"
if ( not defined %Win32::TieRegistry:: ){
use Win32::TieRegistry( Delimiter=>'/' );
}
my $Regkey
= "//$machine/HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows
NT/CurrentVersion/Winlogon/";
my $Regval = "/CachePrimaryDomain";
my $RegObject = $Registry->Open( $Regkey, { Access=>KEY_READ } );
if ( defined $RegObject->{ $Regval } ){
$Domain{ $machine } = $RegObject->{ $Regval };
return $Domain{ $machine };
}
}
warn "ERROR: UNABLE TO OPEN REGISTRY ON $machine. DOMAIN NOT RESOLVED!
\n";
}
__END__
Regards,
Tony
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs