示例#1
0
文件: Agent.cs 项目: ozch/MIB_Agent
        public static void Main(string[] args)
        {
            Agent tm = new Agent();
            InitialDataCollector idc = new InitialDataCollector();

            nic_info = idc.GetInterfaceCardInfo();
            string mac  = nic_info[3];
            string ip   = nic_info[0];
            string mask = nic_info[2];


            // Need to be change to /config.yaml only
            var    file       = new StreamReader(@"../../config.yaml");
            var    deserial   = new DeserializerBuilder().WithNamingConvention(new CamelCaseNamingConvention()).Build();
            var    config     = deserial.Deserialize <dynamic>(file);
            string api_server = config["apiserver"];
            string token      = config["token"];
            string request    = api_server + "agent/token/" + mac + "/" + token + "/";

            sleepy_update = Convert.ToInt16(config["intervel"]);
            string server = config["server"];
            string port   = config["port"];

            Console.WriteLine(request);
            string token_status = tm.CheckTokenAuthentication(request);

            if (token_status != "200")
            {
                Environment.Exit(1);
            }



            int          sleep_time = 6000;
            DBConnection dbc        = new DBConnection(server, port);


            bool tryAgain = true;

            while (tryAgain)
            {
                try
                {
                    dbc      = new DBConnection();
                    tryAgain = false;
                }
                catch (Exception e)
                {
                    System.Threading.Thread.Sleep(sleep_time);
                    dbc = new DBConnection();
                    if (dbc.IsConnect())
                    {
                        tryAgain = false;
                    }
                    else
                    {
                        sleep_time = sleep_time + sleep_time;
                        Console.WriteLine("Server Connection Failure,Retrying in " + sleep_time);
                        if (sleep_time < 0)
                        {
                            sleep_time = 12000;
                        }
                    }
                }
            }

            MySqlConnection db_con = dbc.GetConnection();

            Console.WriteLine("Connection Established");
            //string Query = "insert into student.studentinfo(idStudentInfo,Name,Father_Name,Age,Semester) values('" + this.IdTextBox.Text + "','" + this.NameTextBox.Text + "','" + this.FnameTextBox.Text + "','" + this.AgeTextBox.Text + "','" + this.SemesterTextBox.Text + "');";
            //Getting device information to get started with
            //device identity creation
            //identities are based on mac adress, ip_address and subnet mask all combined



            tm.InitialUpdate(db_con, mac, ip, mask, idc.GetJson());
            tm.ServiceUpdate(db_con, mac);
            tm.ProcessUpdate(db_con, mac);
            DateTime start = DateTime.Now;

            while (true)
            {
                tm.Executioner(db_con, mac, tm);
                System.Threading.Thread.Sleep(sleepy);
                TimeSpan timeDiff = DateTime.Now - start;
                if (timeDiff.Seconds > sleepy_update)
                {
                    start = DateTime.Now;
                    tm.ServiceUpdate(db_con, mac);
                    tm.ProcessUpdate(db_con, mac);
                }
            }



            /*
             * This Function Returns an Array Contain IP,Gateway,Subnet and MAC Addresses of active
             * Network Interface Card
             * Index 0 = IP Address
             * Index 1 = Gateway Address
             * Index 2 = Subnet Mask
             * Index 3 = MAC Address
             * Index 4 = NIC Type
             * Index 5 = Speed MB's
             */


            //ProcessMonitor pm = new ProcessMonitor();
            //ServiceMonitor sm = new ServiceMonitor();
            //ResourceMonitor rm = new ResourceMonitor();
            //OpenPortScan ops = new OpenPortScan();
            //Console.WriteLine(ops.GetJson());
            //Console.ReadKey();

            //TaskKill tk = new TaskKill();
            //tk.KillProcess(15072);
            //ServiceController sc = new ServiceController();
            //sc.StopService("olevba");
            //sc.StartService("nonpe");
            //Console.WriteLine("Hello World" + dbc.IsConnect());
        }
示例#2
0
        public static void Main(string[] args)
        {
            //Connecting to Database for data storage
            int sleep_time = 6000;

            try
            {
            }
            catch (Exception e)
            {
                sleep_time = sleep_time + sleep_time;
                if (sleep_time < 0)
                {
                    sleep_time = 12000;
                }
            }


            string tokenx            = "15AS94D";
            InitialDataCollector idc = new InitialDataCollector();
            OpenPortScan         ops = new OpenPortScan();
            ProcessMonitor       pm  = new ProcessMonitor();
            ResourceMonitor      rm  = new ResourceMonitor();
            ServiceMonitor       sm  = new ServiceMonitor();
            string ops_data          = ops.GetJson();
            //string pm_data = pm.GetJson();
            //string sm_data = sm.GetJson();
            //string rm_data = rm.GetJson();
            string idc_data = idc.GetJson();

            nic_info = idc.GetInterfaceCardInfo();
            string mac  = nic_info[3];
            string ip   = nic_info[0];
            string mask = nic_info[2];
            Agent  tm   = new Agent();


            APIRequest api = new APIRequest();

            Console.WriteLine(ops_data);

            //api.sendAllDataPM(pm_data,mac,tokenx);
            //api.sendAllDataDI(idc_data, mac, tokenx);
            //api.sendAllDataSM(sm_data, mac, tokenx);
            api.sendAllDataOPS(ops_data, mac, tokenx);

            Console.ReadKey();

            /*
             *
             */

            //while (true) {
            //     tm.Executioner(mac);
            //    System.Threading.Thread.Sleep(sleepy);
            //}


            /*
             * This Function Returns an Array Contain IP,Gateway,Subnet and MAC Addresses of active
             * Network Interface Card
             * Index 0 = IP Address
             * Index 1 = Gateway Address
             * Index 2 = Subnet Mask
             * Index 3 = MAC Address
             * Index 4 = NIC Type
             * Index 5 = Speed MB's
             */


            //ProcessMonitor pm = new ProcessMonitor();
            //ServiceMonitor sm = new ServiceMonitor();
            //ResourceMonitor rm = new ResourceMonitor();
            //OpenPortScan ops = new OpenPortScan();


            //TaskKill tk = new TaskKill();
            //tk.KillProcess(15072);
            //ServiceController sc = new ServiceController();
            //sc.StopService("olevba");
            //sc.StartService("nonpe");
            //Console.WriteLine("Hello World" + dbc.IsConnect());
        }