public string ServiceUpdate(MySqlConnection con, string mac) { string stm = string.Format("select * from mib.services_info where mac_address='{0}'", mac); MySqlCommand cmd = con.CreateCommand(); cmd.CommandText = stm; ServiceMonitor sm = new ServiceMonitor(); int number = sm.GetNumber(); Console.WriteLine(number); string json = sm.GetJson(); //change it to ExecuteScaler(); var scal = cmd.ExecuteScalar(); Console.WriteLine(scal); if (scal != null) { string query = string.Format("UPDATE mib.services_info SET mac_address = '{0}', services_info = '{1}', total = {2} WHERE mac_address = '{0}'", mac, json, number); cmd = con.CreateCommand(); cmd.CommandText = query; cmd.ExecuteNonQuery(); Console.WriteLine("Ran UPDATE"); return("0"); } else { string query = string.Format("INSERT INTO mib.services_info(mac_address, services_info, total) VALUES ('{0}','{1}',{2})", mac, json, number); cmd = con.CreateCommand(); cmd.CommandText = query; cmd.ExecuteNonQuery(); Console.WriteLine("Ran Insert"); return("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()); }