예제 #1
0
 private void ProcessTh()
 {
     // 实现异步接受消息的方法 客户端不断监听消息
     clientSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveMsg), clientSocket);
     while (!Offline)
     {
         GetInfo getInfo = new GetInfo();
         // 发送进程心跳包
         Dictionary <int, string> processInfo = getInfo.GetProcessInfo();
         Hashtable ht = new Hashtable();
         foreach (KeyValuePair <int, string> itemInfo in processInfo)
         {
             ht.Add(itemInfo.Key.ToString(), itemInfo.Value.ToString());
             // 显示日志内容
             string showIndex = "PID:" + itemInfo.Key.ToString() + "----PNAME:" + itemInfo.Value.ToString() + "\n";
             string Log       = Config.OutputLog(showIndex);
             Console.WriteLine(Log);
         }
         JavaScriptSerializer js = new JavaScriptSerializer();
         string sendJs           = js.Serialize(ht);
         string sendStr          = sendJs.ToString();
         SentMsg(sendStr);
         Thread.Sleep(1000 * 60 * 2);
     }
 }
예제 #2
0
        /**
         * 获得电脑的基本信息
         * */
        private void Btn_Get_Info(object sender, RoutedEventArgs e)
        {
            GetInfo getInfo = new GetInfo();
            string  Ip      = getInfo.GetIpInfo();
            string  Mac     = getInfo.GetMacInfo();
            Dictionary <int, string> process = getInfo.GetProcessInfo();

            this.IpBox.Text  = Ip;
            this.MacBox.Text = Mac;
        }
예제 #3
0
        /**
         * 设置托盘
         * */
        private void InitialTray()
        {
            // 获得电脑信息
            GetInfo getInfo = new GetInfo();
            string  Ip      = getInfo.GetIpInfo();
            string  Mac     = getInfo.GetMacInfo();
            Dictionary <int, string> process = getInfo.GetProcessInfo();

            //设置托盘的各个属性
            notifyIcon = new System.Windows.Forms.NotifyIcon();
            // 设置托盘图标
            notifyIcon.Icon = new System.Drawing.Icon(System.Windows.Forms.Application.StartupPath + "\\computer.ico");
            // 是否显示图标
            notifyIcon.Visible = true;

            //设置菜单项
            // System.Windows.Forms.MenuItem SetUp = new System.Windows.Forms.MenuItem("设置");
            // 鼠标点击设置 显示主窗体
            // SetUp.Click += Show_MainWindows;

            // 显示电脑IP菜单项
            System.Windows.Forms.MenuItem IP = new System.Windows.Forms.MenuItem(Ip);

            //退出菜单项
            System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("退出");
            // 退出按钮--退出输入密码
            exit.Click += Exit_Click;

            //关联托盘控件
            System.Windows.Forms.MenuItem[] childen = new System.Windows.Forms.MenuItem[] { IP, exit };
            notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(childen);

            // 链接服务器
            connect_socket();
            // 第一次链接发送信息
            sent_msg(Ip, Mac);
            Thread.Sleep(1000 * 2);
            // 发送进程
            sent_process(process);
        }
예제 #4
0
        /**
         * 向服务器发送进程信息
         * */
        private void SendProcess_Click(object sender, RoutedEventArgs e)
        {
            GetInfo getInfo = new GetInfo();
            Dictionary <int, string> processInfo = getInfo.GetProcessInfo();
            Hashtable ht = new Hashtable();

            foreach (KeyValuePair <int, string> itemInfo in processInfo)
            {
                ht.Add(itemInfo.Key.ToString(), itemInfo.Value.ToString());
                // 显示日志内容
                string showIndex = "PID:" + itemInfo.Key.ToString() + "----PNAME:" + itemInfo.Value.ToString() + "\n";
                string Log       = Config.OutputLog(showIndex);
                this.Log.AppendText(Log);
                // 下拉框显示内容
                this.ProcessItemName.Items.Add(itemInfo.Value.ToString());
            }
            JavaScriptSerializer js = new JavaScriptSerializer();
            string sendJs           = js.Serialize(ht);
            string sendStr          = sendJs.ToString();

            tcInt.SentMsg(sendStr);
        }
예제 #5
0
        /**
         * 功能描述:向服务器端发送消息以及心跳包
         * */
        private void SendMsg_Click(object sender, RoutedEventArgs e)
        {
            // 获得信息进行发送
            GetInfo getInfo = new GetInfo();
            string  Ip      = getInfo.GetIpInfo();
            string  Mac     = getInfo.GetMacInfo();

            Hashtable ht = new Hashtable();

            ht.Add("ip", Ip);
            ht.Add("mac", Mac);
            ht.Add("command", "Heartbeat");

            JavaScriptSerializer js = new JavaScriptSerializer();
            string sendJs           = js.Serialize(ht);
            string sendStr          = sendJs.ToString();

            // Send Message
            tcInt.SentMsg(sendStr);
            Thread.Sleep(1000 * 2);
            // 开始心跳线程
            tcInt.Start();
        }