Friday, April 21, 2017

Manipulate WMI through Perl

Online Library:


Inquery Tool:


An example of manipulating WMI through Perl
--------------------------------------------
#!/usr/bin/perl -w
#use strict;
#Execute a command:
#wmic /node:remote_computer process call create "netstat.exe -ano"
use Win32::OLE;
$|=1;

print("Target IP: ");
$target=<STDIN>;
chop($target);

#my ( $ServiceSet, $Service );

eval { $NetworkAdapters = Win32::OLE->GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\".$target."\\Root\\CIMv2")->ExecQuery("SELECT * FROM Win32_NetworkAdapter"); };
unless($@){
                print "\n";
                foreach $Adapter (in $NetworkAdapters){
                                print $Adapter->{Name}, "\n";
                                print $Adapter->{Description}, "\n";
                }
}else{
                print STDERR Win32::OLE->LastError, "\n";
}
--------------------------------------------
 

No comments:

Post a Comment