public void UpdateNewRecord(SystemFound systemData) { if (this.InvokeRequired) { this.BeginInvoke(new UpdateNewRecordDelegate(this.UpdateNewRecord), new object[] { systemData }); return; } if (this.targetStringList.Contains(systemData.IpAddress) == true) { LogCons.Inst.Write(LogLevel.Debug, $"ArpScan.UpdateTextBox(): {systemData.MacAddress}/{systemData.IpAddress} already exists"); return; } try { // Determine vendor string vendor = this.macVendorHandler.GetVendorByMac(systemData.MacAddress); if (systemData.IpAddress != this.gatewayIp && systemData.IpAddress != this.localIp) { this.targetStringList.Add(systemData.IpAddress); this.TargetList.Add(new TargetRecord(systemData.IpAddress, systemData.MacAddress, vendor)); LogCons.Inst.Write(LogLevel.Info, $"UpdateNewRecord(): Found new target system {systemData.MacAddress}/{systemData.IpAddress}"); } } catch (Exception ex) { LogCons.Inst.Write(LogLevel.Error, ex.StackTrace); } }
private SystemFound ParseSystemDataFromXml(string data) { // Extract newly detected system XDocument xmlContent = XDocument.Parse(data); var packetEntries = from service in xmlContent.Descendants("arp") select new { Type = service.Element("type").Value, IpAddress = service.Element("ip").Value, MacAddress = service.Element("mac").Value }; if (packetEntries == null) { throw new Exception("Could not parse data from XML structure."); } else if (packetEntries.Count() <= 0) { throw new Exception("Could not create an object from the XML structure"); } else if (packetEntries.Count() > 1) { throw new Exception("More than one object was generated from the XML structure"); } var tmpType = packetEntries.First(); var newSystem = new SystemFound(tmpType.MacAddress, tmpType.IpAddress, tmpType.Type.ToLower().Trim()); return(newSystem); }
public void NotifyArpResponseNewRecord(SystemFound newSystem) { foreach (var observer in this.observersArpResponse) { observer.UpdateNewRecord(newSystem); } }
public void UpdateNewRecord(SystemFound systemData) { if (this.InvokeRequired) { this.BeginInvoke(new UpdateNewRecordDelegate(this.UpdateNewRecord), new object[] { systemData }); return; } if (systemData.Type != "reply") { return; } lock (this.targetStringList) { // Add new record line if system does not exist if (this.targetStringList.Where(elem => elem.IpAddress == systemData.IpAddress).ToList().Count <= 0) { try { // Determine vendor string vendor = this.macVendorHandler.GetVendorByMac(systemData.MacAddress); if (systemData.IpAddress != this.minaryObj.MinaryTaskFacade.CurrentMinaryConfig.GatewayIp && systemData.IpAddress != this.minaryObj.MinaryTaskFacade.CurrentMinaryConfig.LocalIp) { this.targetStringList.Add(new SystemFoundSimple(systemData.MacAddress, systemData.IpAddress)); LogCons.Inst.Write(LogLevel.Info, $"GuiSimpleUserControl/UpdateNewRecord(): Found new target system {systemData.MacAddress}/{systemData.IpAddress}"); } } catch (Exception ex) { LogCons.Inst.Write(LogLevel.Error, ex.StackTrace); } } else { LogCons.Inst.Write(LogLevel.Info, $"GuiSimpleUserControl/UpdateNewRecord(): Redetected target system {systemData.MacAddress}/{systemData.IpAddress}"); } // Update "last seen" timestamp var rec = this.targetStringList.Where(elem => elem.MacAddress == systemData.MacAddress).FirstOrDefault(); if (rec != null) { var now = DateTime.Now; TimeSpan span = now.Subtract(rec.LastSeen); rec.LastSeen = now; try { rec.LastSeenSpan = span.ToString(@"hh\:mm\:ss"); } catch (Exception ex) { var la = ex.Message; } } } }
public void AddNewRecord_Success() { var guiSimple = this.GenerateGuiSimple(); var newRecord = new SystemFound("00-11-22-33-44-55", "192.168.1.2"); guiSimple.UpdateNewRecord(newRecord); guiSimple.RemoveOutdatedRecords(); Assert.IsTrue(guiSimple.TargetStringList.Count == 1); }
public void RemoveOutdatedRecord2_Success() { var guiSimple = this.GenerateGuiSimple(); var newRecord = new SystemFound("00-11-22-33-44-55", "192.168.1.2"); guiSimple.UpdateNewRecord(newRecord); Assert.IsTrue(guiSimple.TargetStringList.Count == 1); guiSimple.TargetStringList[0].LastSeen = DateTime.Now.AddSeconds(-178); guiSimple.RemoveOutdatedRecords(); Assert.IsTrue(guiSimple.TargetStringList.Count == 1); }
public void RemoveOutdatedRecord1_Success() { var simpleGui = this.GenerateSimpleGui(); var newRecord = new SystemFound("00-11-22-33-44-55", "192.168.1.2"); simpleGui.UpdateNewRecord(newRecord); Assert.IsTrue(simpleGui.TargetStringList.Count == 1); simpleGui.TargetStringList[0].LastSeen = DateTime.Now.AddSeconds(-182); simpleGui.RemoveOutdatedRecords(); Assert.IsTrue(simpleGui.TargetStringList.Count == 0); }
public void UpdateNewRecord(SystemFound systemData) { if (this.InvokeRequired) { this.BeginInvoke(new UpdateNewRecordDelegate(this.UpdateNewRecord), new object[] { systemData }); return; } lock (this.targetStringList) { // Add new record line if system does not exist if (this.targetStringList.Where(elem => elem.IpAddress == systemData.IpAddress).ToList().Count <= 0) { try { // Determine vendor string vendor = this.macVendorHandler.GetVendorByMac(systemData.MacAddress); if (systemData.IpAddress != this.arpScanConfig.GatewayIp && systemData.IpAddress != this.arpScanConfig.LocalIp) { this.targetStringList.Add(new SystemFoundSimple(systemData.MacAddress, systemData.IpAddress)); LogCons.Inst.Write(LogLevel.Info, $"SimpleGuiUserControl/UpdateNewRecord(): Found new target system {systemData.MacAddress}/{systemData.IpAddress}"); } } catch (Exception ex) { LogCons.Inst.Write(LogLevel.Error, ex.StackTrace); } } else { LogCons.Inst.Write(LogLevel.Info, $"SimpleGuiUserControl/UpdateNewRecord(): Redetected target system {systemData.MacAddress}/{systemData.IpAddress}"); } // Update "last seen" timestamp var rec = this.targetStringList.Where(elem => elem.MacAddress == systemData.MacAddress).FirstOrDefault(); if (rec != null) { rec.LastSeen = DateTime.Now; } } }
private void PacketHandler(Packet packet) { if (packet == null || packet.Length <= 0 || packet.IsValid == false) { return; } if (packet.Ethernet.EtherType != EthernetType.Arp || packet.Ethernet.Arp.Operation != ArpOperation.Reply) { return; } var senderMac = string.Join("-", this.ByteToHexString(packet.Ethernet.Arp.SenderHardwareAddress.ToArray())); var senderIp = new System.Net.IPAddress(packet.Ethernet.Arp.SenderProtocolAddress.ToArray()).ToString(); SystemFound newRecord = new SystemFound(senderMac, senderIp); this.NotifyNewRecord(newRecord); }
public void NotifyNewRecord(SystemFound systemData) { this.observers.ForEach(elem => elem.UpdateNewRecord(systemData)); }
protected void TriggerSystemFound(GameConsole system) { SystemFound?.Invoke(system); }