Advertisement
Guest User

WMI Client

a guest
Jul 19th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.67 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3. using System.Management;
  4.  
  5. class TestProgram {
  6.  
  7.     public static void test(object ip) {
  8.  
  9.         string target = (string)ip;
  10.  
  11.         ConnectionOptions options = new ConnectionOptions();
  12.         options.Username = "Administrator";
  13.         options.Password = "dRum&5853";
  14.         options.Authentication = (AuthenticationLevel)Enum.Parse(typeof(AuthenticationLevel), "Packet");
  15.         options.Impersonation = (ImpersonationLevel)Enum.Parse(typeof(ImpersonationLevel), "Impersonate");
  16.         options.Authority = "ntlmdomain:WORKGROUP";
  17.  
  18.  
  19.         ManagementScope scope = new ManagementScope( "\\\\" + target + "\\root\\cimv2", options );
  20.    
  21.         try {
  22.             scope.Connect();
  23.     //      Console.WriteLine("Connection successful.");
  24.         } catch (Exception e) {
  25.             Console.WriteLine("An exception has occured for IP address " + target);
  26.             Console.WriteLine(e.Message);
  27.             System.Environment.Exit(1);
  28.         }
  29.  
  30.         string[] WMIClasses = {"Win32_PerfFormattedData_PerfDisk_LogicalDisk","Win32_PerfFormattedData_PerfOS_Memory","Win32_PerfFormattedData_PerfDisk_PhysicalDisk","Win32_PerfFormattedData_PerfOS_Processor"};
  31.  
  32.         foreach (string WMIClass in WMIClasses) {
  33.             SelectQuery query = new SelectQuery(WMIClass, " name IS NOT NULL OR name IS NULL" );
  34.             ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
  35.    
  36.             try {
  37.                 ManagementObjectCollection result = searcher.Get();
  38. //              Console.WriteLine("There are " + result.Count + " rows.");
  39.  
  40.                 if (result.Count == 0) {
  41.                     Console.WriteLine("There are 0 results in " + target + " for class " + WMIClass);
  42.                 }
  43.    
  44.                 foreach( ManagementBaseObject row in result ) {
  45.                     foreach( PropertyData property in row.Properties ) {
  46.     //                  Console.WriteLine(property.Name + " = " + property.Value);
  47.                     }
  48.                 }
  49.    
  50.             } catch (Exception e) {
  51.                 Console.WriteLine("An exception has occured when running query for " + target);
  52.                 Console.WriteLine(e.Message);
  53.                 System.Environment.Exit(1);
  54.             }
  55.         }
  56.  
  57. //      Thread.Sleep(5000);
  58.         test(ip);
  59.  
  60.     }
  61.  
  62.     public static void Main(string[] args) {
  63.  
  64.         string[] ips = {"10.129.12.121","10.129.12.121","10.129.12.122","10.129.12.123","10.129.12.124","10.129.12.125","10.129.12.126","10.129.12.135","10.129.12.138","10.129.12.140","10.129.12.160","10.129.12.161","10.129.12.162","10.129.12.163","10.129.12.164","10.129.12.171","10.129.12.174","10.129.12.182","10.129.12.196","10.129.12.197","10.129.12.198","10.129.12.199","10.129.12.218","10.129.12.219","10.129.12.22","10.129.12.225","10.129.12.226","10.129.12.227","10.129.12.228","10.129.12.23","10.129.12.234","10.129.12.236","10.129.12.246","10.129.12.247","10.129.12.248","10.129.12.249","10.129.12.26","10.129.12.27","10.129.12.38","10.129.12.43","10.129.12.48","10.129.12.52","10.129.12.55","10.129.12.69","10.129.12.79","10.129.12.84","10.129.12.85","10.129.12.99","10.129.13.120","10.129.13.163","10.129.13.167","10.129.13.180","10.129.13.195","10.129.13.204","10.129.13.205","10.129.13.206","10.129.13.216","10.129.13.23","10.129.13.24","10.129.13.254","10.129.13.32","10.129.13.33","10.129.13.37","10.129.13.38","10.129.13.39","10.129.13.44","10.129.13.45","10.129.13.48","10.129.13.57","10.129.13.59","10.129.13.60","10.129.13.61","10.129.13.63","10.129.14.1","10.129.14.103","10.129.14.11","10.129.14.124","10.129.14.139","10.129.14.142","10.129.14.148","10.129.14.201","10.129.14.218","10.129.14.35","10.129.14.50","10.129.14.57","10.129.14.68","10.129.14.83","10.129.15.101","10.129.15.128","10.129.15.143","10.129.15.151","10.129.15.32","10.129.15.38","10.129.15.51","10.129.15.52","10.129.15.57","10.129.15.59","10.129.15.6","10.129.15.70","10.129.15.82"};
  65.  
  66.         foreach (string ip in ips) {
  67.             Thread newThread = new Thread(test);
  68.             newThread.Start(ip);
  69.         }
  70.     }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement