-
Notifications
You must be signed in to change notification settings - Fork 0
/
wmi_save_db.pl
executable file
·77 lines (69 loc) · 3.19 KB
/
wmi_save_db.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/perl -w
# use strict;
use Win32::OLE('in');
use DBI;
use constant bFlagReturnImmediately => 0x10;
use constant bFlagForwardOnly => 0x20;
$range = `C:\\Users\\Administrator\\wmi\\Nmap\\nmap -sP 10.36.11.0/24`;
$dbh = DBI->connect('dbi:mysql:wmi:10.36.11.150','wmi','wmi') or warn "Connection Error: $DBI::errstr\n";
my $warehouse = "WAREHOUSE_03";
my @computers = ($range =~ m/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/g);
foreach my $computer (@computers)
{
if (my $oWMIService = Win32::OLE->GetObject( "winmgmts:\\\\$computer\\root\\CIMV2")) {
my $colItems = $oWMIService->ExecQuery ( "SELECT * FROM Win32_ComputerSystem", "WQL", bFlagReturnImmediately | bFlagForwardOnly);
foreach my $objItem (in $colItems) {
$name = $objItem->{Name};
$caption = $objItem->{Caption};
$domain = $objItem->{Domain};
$manufacturer = $objItem->{Manufacturer};
$model = $objItem->{Model};
$ip = $computer;
}
my $osItems = $oWMIService->ExecQuery ( "SELECT * FROM Win32_OperatingSystem", "WQL", bFlagReturnImmediately | bFlagForwardOnly);
foreach my $objItem (in $osItems)
{
$os_caption = $objItem->{Caption};
$os_buildnum = $objItem->{BuildNumber};
$os_build = $objItem->{BuildType};
$os_version = $objItem->{Version};
$os_serialnumber = $objItem->{SerialNumber};
}
my $diskItems = $oWMIService->ExecQuery ( "SELECT * FROM Win32_LogicalDisk", "WQL", bFlagReturnImmediately | bFlagForwardOnly);
foreach my $objItem (in $diskItems)
{
$device_id = $objItem->{DeviceID};
$file_system = $objItem->{FileSystem};
$volume_serial_number = $objItem->{VolumeSerialNumber};
$size = $objItem->{Size};
$free_space = $objItem->{FreeSpace};
$dbh->do("INSERT INTO disks(warehouse,name,ip,device_id,file_system,serial_number,size,free_space)
VALUES (?,?,?,?,?,?,?,?)",
undef,
$warehouse, $name, $ip, $device_id, $file_system, $volume_serial_number, $size, $free_space);
}
$dbh->do("INSERT INTO equipment(warehouse,name,caption,domain,manufacturer,model,ip,os_caption,os_buildnum,os_build,os_version,os_serialnumber)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?)",
undef,
$warehouse, $name, $caption, $domain, $manufacturer, $model, $ip, $os_caption, $os_buildnum, $os_build, $os_version, $os_serialnumber);
my $softwareItems = $oWMIService->ExecQuery ( "SELECT * FROM Win32_Product", "WQL", bFlagReturnImmediately | bFlagForwardOnly);
foreach my $objItem (in $softwareItems)
{
$sname = $objItem->{Name};
$description = $objItem->{Description};
$vendor = $objItem->{Vendor};
$version = $objItem->{Version};
$install_date = $objItem->{InstallDate};
$install_location = $objItem->{InstallLocation};
$package_code = $objItem->{PackageCode};
$product_id = $objItem->{ProductID};
$reg_company = $objItem->{RegCompany};
$reg_owner = $objItem->{RegOwner};
$url_info_about = $objItem->{URLInfoAbout};
$dbh->do("INSERT INTO software(warehouse,name,ip,sname,description,vendor,version,install_date,install_location,package_code,product_id,reg_company,reg_owner,url_info_about)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
undef,
$warehouse, $name, $ip, $sname, $description, $vendor, $version, $install_date, $install_location, $package_code, $product_id, $reg_company, $reg_owner, $url_info_about);
}
}
}