private void BGW_ArpScanSender_DoWork(object sender, DoWorkEventArgs e) { ArpScanConfig arpScanConfig = null; ArpScanner arpScanner = null; try { arpScanConfig = this.GetArpScanConfig(); arpScanner = new ArpScanner(arpScanConfig); } catch (Exception ex) { LogCons.Inst.Write(LogLevel.Error, $"BGW_ArpScanSender(EXCEPTION): {ex.Message}\r\n{ex.StackTrace}"); this.SetArpScanGuiOnStopped(); } try { arpScanner.AddObserverArpRequest(this); arpScanner.AddObserverCurrentIp(this); arpScanner.StartScanning(); } catch (Exception ex) { LogCons.Inst.Write(LogLevel.Error, $"BGW_ArpScanSender(EXCEPTION2): {ex.Message}\r\n{ex.StackTrace}"); this.SetArpScanGuiOnStopped(); return; } }
public void ArpScanner_Constructor_Succeeds() { // Act var sut = new ArpScanner(_processWrapperFactory); // Assert Assert.IsNotNull(sut); Assert.IsInstanceOfType(sut, typeof(IArpScanner)); }
public void ArpScanner_GetRespondingMachines_Starts_ArpScan_Process() { // Arrange IProcessWrapper mockProcessWrapper = GetMockProcessWrapper(new string[] { null }); _processWrapperFactory.Stub(x => x.GetNewProcessWrapper()).Return(mockProcessWrapper); var sut = new ArpScanner(_processWrapperFactory); // Act sut.GetRespondingMachines(); // Assert mockProcessWrapper.AssertWasCalled(x => x.Start(), options => options.Repeat.Once()); }
/// <summary> /// Test runner - Test that GetRespondingMachines continues if ReadLine content is invalid. /// </summary> /// <param name="content">ReadLine content.</param> private void GetRespondingMachinesShouldContinueIfReadLineContentInvalid_TestRunner(string content) { // Arrange IProcessWrapper mockProcessWrapper = GetMockProcessWrapper(new string[] { content, null }); _processWrapperFactory.Stub(x => x.GetNewProcessWrapper()).Return(mockProcessWrapper); var sut = new ArpScanner(_processWrapperFactory); // Act IEnumerable <IPAddress> scanResults = sut.GetRespondingMachines(); // Assert Assert.IsFalse(scanResults.Any()); }
public void ArpScanner_GetResponding_Machines_Only_Returns_Valid_IP_Addresses() { // Arrange const int IP_ADDRESS_COUNT = 1; const string INVALID_IP_ADDRESS = "300.0.0.1"; const string VALID_IP_ADDRESS = "127.0.0.1"; IProcessWrapper mockProcessWrapper = GetMockProcessWrapper(new string[] { INVALID_IP_ADDRESS + " OK", VALID_IP_ADDRESS + " OK", null }); _processWrapperFactory.Stub(x => x.GetNewProcessWrapper()).Return(mockProcessWrapper); var sut = new ArpScanner(_processWrapperFactory); // Act IEnumerable <IPAddress> scanResults = sut.GetRespondingMachines(); // Assert Assert.AreEqual(IP_ADDRESS_COUNT, scanResults.Count()); Assert.AreEqual(VALID_IP_ADDRESS, scanResults.First().ToString()); }
public void ArpScanner_GetRespondingMachines_Should_Return_Responding_IP_Address_List() { // Arrange const int IP_ADDRESS_COUNT = 2; const string IP_ADDRESS1 = "127.0.0.1"; const string IP_ADDRESS2 = "192.168.1.1"; IProcessWrapper mockProcessWrapper = GetMockProcessWrapper(new string[] { IP_ADDRESS1 + " OK", IP_ADDRESS2 + " OK", null }); _processWrapperFactory.Stub(x => x.GetNewProcessWrapper()).Return(mockProcessWrapper); var sut = new ArpScanner(_processWrapperFactory); // Act IEnumerable <IPAddress> scanResults = sut.GetRespondingMachines(); // Assert Assert.AreEqual(IP_ADDRESS_COUNT, scanResults.Count()); Assert.AreEqual(IP_ADDRESS1, scanResults.ElementAt(0).ToString()); Assert.AreEqual(IP_ADDRESS2, scanResults.ElementAt(1).ToString()); }
private void SimpleGuiUserControl_VisibleChanged(object sender, EventArgs e) { if (this.Visible == false || this.Disposing == true) { this.bgw_ArpScanSender.CancelAsync(); this.bgw_ArpScanListener.CancelAsync(); this.bgw_RemoveInactiveSystems.CancelAsync(); this.minaryObj?.MinaryAttackServiceHandler?.StopAllServices(); LogCons.Inst.Write(LogLevel.Info, "SimpleGuiUserControl/SimpleGuiUserControl_VisibleChanged: SimpleGUI/ARPScan/AttackServices stopped"); return; } // Configure ARP scan object //this.arpScanner.Config = this.GetArpScanConfig(); // Instanciate ARP scanner object try { this.arpScanConfig = this.GetArpScanConfig(); this.arpScanner = new ArpScanner(this.arpScanConfig); } catch (Exception ex) { LogCons.Inst.Write(LogLevel.Error, $"SimpleGuiUserControl/SimpleGuiUserControl_VisibleChanged(EXCEPTION): {ex.Message}\r\n{ex.StackTrace}"); } try { this.replyListener = new ReplyListener(this.arpScanConfig); } catch (Exception ex) { LogCons.Inst.Write(LogLevel.Error, $"SimpleGuiUserControl/BGW_ArpScanListener(EXCEPTION1): {ex.Message}"); return; } try { this.replyListener.AddObserver(this); } catch (Exception ex) { LogCons.Inst.Write(LogLevel.Error, $"SimpleGuiUserControl/BGW_ArpScanListener(EXCEPTION2): {ex.Message}"); return; } this.StartArpScanListener(); this.StartArpScanSender(); this.StartRemoveInactiveSystems(); // Make all plugins prepare their environment before the actual attack begins. this.minaryObj.PrepareAttackAllPlugins(); // After the plugins were prepared start all attack services. try { var currentServiceParams = this.GetCurrentServiceParamsConfig(); this.minaryObj.StartAttackAllServices(currentServiceParams); } catch (Exception ex) { LogCons.Inst.Write(LogLevel.Error, $"SimpleGuiUserControl/BGW_ArpScanListener(EXCEPTION3): {ex.Message}"); return; } LogCons.Inst.Write(LogLevel.Info, "SimpleGuiUserControl/SimpleGuiUserControl_VisibleChanged: SimpleGUI/ARPScan/AttackServices started"); }