/// <summary> /// Opens dialog to select sensor executable manually. /// Gets the filename of selected executable and adds it to the list of sensors to be loaded. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLoadSensor_Click(object sender, EventArgs e) { DialogResult result = ofdSelectSensor.ShowDialog(); if (result == DialogResult.OK) { // get sensor executable title and add it to list Assembly sensorAssembly = Assembly.LoadFrom(ofdSelectSensor.FileName); Type[] types = sensorAssembly.GetExportedTypes(); BaseSensor sensor = Activator.CreateInstance(types[0]) as BaseSensor; string sensorTitle = sensor.Title; if (cmbSensors.Items.Contains(sensorTitle)) { int i = 1; sensorTitle = sensorTitle + " (" + i.ToString() + ")"; while (true) { if (!cmbSensors.Items.Contains(sensorTitle)) { break; } } } cmbSensors.Items.Add(sensorTitle); _sensorPaths.Add(ofdSelectSensor.FileName); cmbSensors.SelectedIndex = cmbSensors.Items.Count - 1; EnableSensorRemoval(); } }
static void Main(string[] args) { List<Ids.Common.Interfaces.ISensorReport> reporters = new List<Ids.Common.Interfaces.ISensorReport>(); reporters.Add(new Ids.Common.Reporters.SimpleReportAgent()); CaptureDeviceDescription cdd = new CaptureDeviceDescription() { DeviceNumber = 0, TextInDeviceName = "whatever" }; string enteredChar = "X"; while (enteredChar != "s" && enteredChar != "p") { Console.WriteLine("enter type Statistics Capture (s) or Packet Capture (p):"); enteredChar = Console.ReadLine(); } BaseSensor baseSensor = null; if (enteredChar == "p") { //baseSensor = new BaseSensor(cdd, "tcp and ip and dst port 80", SharpPcap.DeviceMode.Normal,reporters, 1000, Enumerations.SensorMode.PacketCapture); baseSensor = new BaseSensor(cdd, "dst 192.168.0.103", SharpPcap.DeviceMode.Normal, reporters, 10000, Enumerations.SensorMode.PacketCapture); } else { baseSensor = new BaseSensor(cdd, "tcp", SharpPcap.DeviceMode.Normal,reporters, 1000, Enumerations.SensorMode.Statistics); } baseSensor.StartCapturing(); Console.ReadLine(); baseSensor.StopCapturing(); }
static void Main(string[] args) { List <Ids.Common.Interfaces.ISensorReport> reporters = new List <Ids.Common.Interfaces.ISensorReport>(); reporters.Add(new Ids.Common.Reporters.SimpleReportAgent()); CaptureDeviceDescription cdd = new CaptureDeviceDescription() { DeviceNumber = 0, TextInDeviceName = "whatever" }; string enteredChar = "X"; while (enteredChar != "s" && enteredChar != "p") { Console.WriteLine("enter type Statistics Capture (s) or Packet Capture (p):"); enteredChar = Console.ReadLine(); } BaseSensor baseSensor = null; if (enteredChar == "p") { //baseSensor = new BaseSensor(cdd, "tcp and ip and dst port 80", SharpPcap.DeviceMode.Normal,reporters, 1000, Enumerations.SensorMode.PacketCapture); baseSensor = new BaseSensor(cdd, "dst 192.168.0.103", SharpPcap.DeviceMode.Normal, reporters, 10000, Enumerations.SensorMode.PacketCapture); } else { baseSensor = new BaseSensor(cdd, "tcp", SharpPcap.DeviceMode.Normal, reporters, 1000, Enumerations.SensorMode.Statistics); } baseSensor.StartCapturing(); Console.ReadLine(); baseSensor.StopCapturing(); }
/// <summary> /// Starts the sensor part. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnStartSensor_Click(object sender, EventArgs e) { // check the sensor part to exists if (!File.Exists(_sensorPaths[cmbSensors.SelectedIndex])) { MessageBox.Show("The sensor part is not found on path " + _sensorPaths[cmbSensors.SelectedIndex] + ". Check the config file or load the part manually using \"Load\" button.", "Sensor part not found.", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // load the sensor part Assembly sensorAssembly = Assembly.LoadFrom(_sensorPaths[cmbSensors.SelectedIndex]); Type[] types = sensorAssembly.GetExportedTypes(); _sensor = Activator.CreateInstance(types[0]) as BaseSensor; _sensor.SetTimerInterval(_discretizationTime); _sensor.FormClosed += sensor_FormClosed; _sensor.OnTemperatureSent += sensorForm_TemperatureSent; _sensor.Show(); // Organize windows _sensor.Location = new Point(5, 10); Location = new Point(10 + _sensor.Size.Width, 10); if (_laser != null) { _laser.Location = new Point(Location.X + Size.Width + 10, 10); } // Disable controls gbSensor.Enabled = false; }
/// <summary> /// When sensor form is closed, the resources must be released. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void sensor_FormClosed(object sender, FormClosedEventArgs e) { _sensor.FormClosed -= sensor_FormClosed; _sensor.OnTemperatureSent -= sensorForm_TemperatureSent; _sensor.Dispose(); _sensor = null; gbSensor.Enabled = true; _isSensorSendingTemperature = false; }
public void CreateWebServerDosSensor_ReturnsSuccess() { //arrange CaptureDeviceDescription cdd = new CaptureDeviceDescription() { DeviceNumber = 0, TextInDeviceName = "whatever" }; List<Ids.Common.Interfaces.ISensorReport> reporters = new List<Ids.Common.Interfaces.ISensorReport>(); reporters.Add(new Ids.Common.Reporters.SimpleReportAgent()); //act BaseSensor baseSensor = new BaseSensor(cdd, "tcp and ip and dst port 80", SharpPcap.DeviceMode.Normal, reporters, 1000, Enumerations.SensorMode.PacketCapture); baseSensor.StartCapturing(); baseSensor.StopCapturing(); //assert Assert.IsNotNull(baseSensor); }
public void CreateWebServerDosSensor_ReturnsSuccess() { //arrange CaptureDeviceDescription cdd = new CaptureDeviceDescription() { DeviceNumber = 0, TextInDeviceName = "whatever" }; List <Ids.Common.Interfaces.ISensorReport> reporters = new List <Ids.Common.Interfaces.ISensorReport>(); reporters.Add(new Ids.Common.Reporters.SimpleReportAgent()); //act BaseSensor baseSensor = new BaseSensor(cdd, "tcp and ip and dst port 80", SharpPcap.DeviceMode.Normal, reporters, 1000, Enumerations.SensorMode.PacketCapture); baseSensor.StartCapturing(); baseSensor.StopCapturing(); //assert Assert.IsNotNull(baseSensor); }
/// <summary> /// Finds sensor executables and populates the dropdown list /// </summary> /// <param name="sensorsPath">Path to sensor executables</param> /// <param name="selectedIndex">Selected index for dropdownlist</param> private void FindSensors(string sensorsPath, JArray userSensors, int selectedIndex) { // First load the sensor executables that are in the sensors folder if (!Path.IsPathRooted(sensorsPath)) { sensorsPath = Path.GetFullPath(Path.Combine(BASE_DIR, sensorsPath)); } ofdSelectSensor.InitialDirectory = sensorsPath; string[] allSensorExes = Directory.GetFiles(sensorsPath, "*.exe", SearchOption.AllDirectories); List <string> sensorTitles = new List <string>(); foreach (string sensorExe in allSensorExes) { if (!sensorExe.Contains("ref")) { _sensorPaths.Add(sensorExe); Assembly sensorAssembly = Assembly.LoadFrom(sensorExe); Type[] types = sensorAssembly.GetExportedTypes(); BaseSensor sensor = Activator.CreateInstance(types[0]) as BaseSensor; sensorTitles.Add(sensor.Title); } } cmbSensors.Items.AddRange(sensorTitles.ToArray()); _numInstalledSensors = sensorTitles.Count; // Finally load the sensors added by user foreach (JToken sensor in userSensors) { cmbSensors.Items.Add(sensor["title"]); _sensorPaths.Add(Path.GetFullPath((string)sensor["path"])); } if (selectedIndex < cmbSensors.Items.Count) { cmbSensors.SelectedIndex = selectedIndex; } EnableSensorRemoval(); }
static void Main(string[] args) { List <Ids.Common.Interfaces.ISensorReport> reporters = new List <Ids.Common.Interfaces.ISensorReport>(); string connectionString = @"Data Source=UB1NB092\SQL2012;Initial Catalog=AzureIdsDb;Persist Security Info=True;User ID=cyberproduct;Password=x2000; Connect Timeout=600;Max Pool Size = 200;Pooling = True"; AzureSqlDbReportAgent cloudDbReportAgent = new AzureSqlDbReportAgent(connectionString, "7C8FA0D3-1F00-42F1-B849-184348D834F6"); reporters.Add(cloudDbReportAgent); reporters.Add(new SimpleReportAgent()); CaptureDeviceDescription cdd = new CaptureDeviceDescription() { DeviceNumber = 0, TextInDeviceName = "whatever" }; string enteredChar = "X"; while (enteredChar != "s" && enteredChar != "p") { Console.WriteLine("enter type Statistics Capture (s) or Packet Capture (p):"); enteredChar = Console.ReadLine(); } BaseSensor baseSensor = null; if (enteredChar == "p") { baseSensor = new BaseSensor(cdd, "port 21", SharpPcap.DeviceMode.Normal, reporters, 20000, Enumerations.SensorMode.PacketCapture); } else { baseSensor = new BaseSensor(cdd, "tcp", SharpPcap.DeviceMode.Normal, reporters, 1000, Enumerations.SensorMode.Statistics); } baseSensor.StartCapturing(); Console.ReadLine(); baseSensor.StopCapturing(); }
static void Main(string[] args) { List<Ids.Common.Interfaces.ISensorReport> reporters = new List<Ids.Common.Interfaces.ISensorReport>(); string connectionString = @"Data Source=UB1NB092\SQL2012;Initial Catalog=AzureIdsDb;Persist Security Info=True;User ID=cyberproduct;Password=x2000; Connect Timeout=600;Max Pool Size = 200;Pooling = True"; AzureSqlDbReportAgent cloudDbReportAgent = new AzureSqlDbReportAgent(connectionString, "7C8FA0D3-1F00-42F1-B849-184348D834F6"); reporters.Add(cloudDbReportAgent); reporters.Add(new SimpleReportAgent()); CaptureDeviceDescription cdd = new CaptureDeviceDescription() { DeviceNumber = 0, TextInDeviceName = "whatever" }; string enteredChar = "X"; while (enteredChar != "s" && enteredChar != "p") { Console.WriteLine("enter type Statistics Capture (s) or Packet Capture (p):"); enteredChar = Console.ReadLine(); } BaseSensor baseSensor = null; if (enteredChar == "p") { baseSensor = new BaseSensor(cdd, "port 21", SharpPcap.DeviceMode.Normal, reporters, 20000, Enumerations.SensorMode.PacketCapture); } else { baseSensor = new BaseSensor(cdd, "tcp", SharpPcap.DeviceMode.Normal, reporters, 1000, Enumerations.SensorMode.Statistics); } baseSensor.StartCapturing(); Console.ReadLine(); baseSensor.StopCapturing(); }
//GameObject BaseSensor.gb //{ // get // { // return gameObject; // } //} /////////////// public int CompareTo(BaseSensor other) { return(other.Priority - priority); }