public IgmpPacketTemplate(IgmpV2Packet packet) { PacketContent = new ObservableCollection <IPacketTemplate> { new IgmpHeaderTemplate(packet) }; }
public IgmpHeaderTemplate(IgmpV2Packet packet) { Type = packet.Type.ToString(); MaxResponseTime = packet.MaxResponseTime.ToString(); Checksum = packet.Checksum.ToString(); GroupAddress = packet.GroupAddress.ToString(); Length = packet.TotalPacketLength.ToString(); }
/* private static int packetIndex = 0; * private void Program_OnPacketArrivalAsync(object sender, CaptureEventArgs e) * { * if (e.Packet.LinkLayerType == PacketDotNet.LinkLayers.Ethernet) * { * var packet = PacketDotNet.Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data); * var ethernetPacket = (PacketDotNet.EthernetPacket)packet; * * _dispatcher.BeginInvoke(new ThreadStart(delegate * { * * _ShowTextBox += (packetIndex + * e.Packet.Timeval.Date.ToString() + * e.Packet.Timeval.Date.Millisecond + * ethernetPacket.SourceHardwareAddress + * ethernetPacket.DestinationHardwareAddress + "\n"); * packetIndex++; * })); * PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ShowTextBox))); * } * }*/ void Program_OnPacketArrivalAsync(object sender, CaptureEventArgs e) { Task.Run(() => { captureFileWriter.Write(e.Packet); }); // парсинг всего пакета Packet packet = Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data); // получение только TCP пакета из всего фрейма TcpPacket tcpPacket = (TcpPacket)packet.Extract <TcpPacket>(); // получение только IP пакета из всего фрейма //IpPacket ipPacket = (IpPacket)packet.Extract(typeof(IpPacket)); // получение только UDP пакета из всего фрейма UdpPacket udpPacket = (UdpPacket)packet.Extract <UdpPacket>(); ArpPacket arpPacket = (ArpPacket)packet.Extract <ArpPacket>(); //LinuxSLLPacket sllPacket = (LinuxSLLPacket)packet.Extract(typeof(LinuxSLLPacket)); IcmpV4Packet icmpPacket = (IcmpV4Packet)packet.Extract <IcmpV4Packet>(); IgmpV2Packet igmpPacket = (IgmpV2Packet)packet.Extract <IgmpV2Packet>(); DateTime time = e.Packet.Timeval.Date.ToLocalTime(); string StrTime = time.Hour + ":" + time.Minute + ":" + time.Second + ":" + time.Millisecond; int len = e.Packet.Data.Length; // Stream myStream; // using (myStream = File.Open(Path.GetTempPath() + "SnifferLogs.pcapng", FileMode.Append, FileAccess.Write)) // { //StreamWriter myWriter = new StreamWriter(myStream); //myWriter.WriteLine(e.Packet); //var thread = new Thread(() => /* Task.Run(() => * { * //captureFileWriter = new CaptureFileWriterDevice(Path.GetTempPath() + "SnifferLogs.pcapng"); * captureFileWriter.Write(e.Packet); * //Thread.Sleep(50); * });*/ // } // using (myStream = File.Open(Path.GetTempPath() + "SnifferLogs.pcapng", FileMode.OpenOrCreate, FileAccess.Read)) // { // StreamReader myReader = new StreamReader(myStream); // Console.Write(myReader.ReadToEnd()); //captureFileReader = new CaptureFileReaderDevice(Path.GetTempPath() + "SnifferLogs.pcapng"); //captureFileReader = new CaptureFileReaderDevice(Path.GetTempPath() + "SnifferLogs.pcapng"); _ShowTextBox += (num + e.Packet.Timeval.Date.ToString() + e.Packet.Timeval.Date.Millisecond + "\n"); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ShowTextBox))); //_ShowTextBox += myReader.ReadToEnd(); // } /* using (myStream = File.Open(Path.GetTempPath() + "SnifferLogs.pcapng", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) * { * StreamWriter myWriter = new StreamWriter(myStream); * StreamReader myReader = new StreamReader(myStream); * //_MainCodeBehind.ShowMessage(e.Packet.ToString()); * myWriter.WriteLine(e.Packet.ToString()); * _ShowTextBox += myReader.ReadLine(); * _MainCodeBehind.ShowMessage(myReader.ReadLine()); * //captureFileWriter = new CaptureFileWriterDevice(Path.GetTempPath() + "SnifferLogs.pcapng"); * //captureFileWriter.Write(e.Packet); * }*/ /* _dispatcher.BeginInvoke(new ThreadStart(delegate * { * * captureFileWriter.Write(e.Packet); * File.Copy(Path.GetTempPath() + "SnifferLogs.pcapng", Path.GetTempPath() + "SnifferLogs2.pcapng"); * })); * _dispatcher.BeginInvoke(new ThreadStart(delegate * { * * _ShowTextBox += (num + * e.Packet.Timeval.Date.ToString() + * e.Packet.Timeval.Date.Millisecond + "\n"); * }));*/ if (tcpPacket != null) { IPPacket ipPacket = (IPPacket)tcpPacket.ParentPacket; Tcp tpck; // порт отправителя tpck.srcPort = tcpPacket.SourcePort; // порт получателя tpck.dstPort = tcpPacket.DestinationPort; tpck.seqNumber = tcpPacket.SequenceNumber; /*значения в десятеричной форме*/ tpck.ackNumber = tcpPacket.AcknowledgmentNumber; tpck.offset = tcpPacket.DataOffset; tpck.flags = tcpPacket.Flags; tpck.CWR = tcpPacket.CongestionWindowReduced; tpck.ECE = tcpPacket.ExplicitCongestionNotificationEcho; tpck.URG = tcpPacket.Urgent; tpck.ACK = tcpPacket.Acknowledgment; tpck.PSH = tcpPacket.Push; tpck.RST = tcpPacket.Reset; tpck.SYN = tcpPacket.Synchronize; tpck.FIN = tcpPacket.Finished; tpck.winSize = tcpPacket.WindowSize; tpck.chksum = tcpPacket.Checksum; tpck.urgpoint = tcpPacket.UrgentPointer; tpck.tdata = Hexdata(tcpPacket); string data = HexToAscii(tcpPacket); _dispatcher.BeginInvoke(new ThreadStart(delegate { Col.Add(new MyTable { Number = num, Time = StrTime, Src = ipPacket.SourceAddress.ToString(), Dst = ipPacket.DestinationAddress.ToString(), Protocol = "TCP", Length = len, Info = Convert.ToString(data) }); tpck.pos = num; TcpCol.Add(tpck); num++; })); } if (udpPacket != null) { IPPacket ipPacket = (IPPacket)udpPacket.ParentPacket; Udp udpk; udpk.srcPort = udpPacket.SourcePort; udpk.dstPort = udpPacket.DestinationPort; udpk.len = udpPacket.Length; udpk.chksum = udpPacket.Checksum; udpk.udata = Hexdata(udpPacket); // данные пакета string data = HexToAscii(udpPacket); _dispatcher.BeginInvoke(new ThreadStart(delegate { Col.Add(new MyTable { Number = num, Time = StrTime, Src = ipPacket.SourceAddress.ToString(), Dst = ipPacket.DestinationAddress.ToString(), Protocol = "UDP", Length = len, Info = Convert.ToString(data) }); udpk.pos = num; UdpCol.Add(udpk); num++; })); } if (arpPacket != null) { Arp arpk; arpk.hwtype = arpPacket.HardwareAddressType.ToString(); arpk.prtype = arpPacket.ProtocolAddressType.ToString(); arpk.hwsize = arpPacket.HardwareAddressLength; arpk.prtsize = arpPacket.ProtocolAddressLength; arpk.opcode = Convert.ToInt16(arpPacket.Operation); arpk.sender_mac = arpPacket.SenderHardwareAddress; arpk.sender_ip = arpPacket.SenderProtocolAddress; arpk.target_mac = arpPacket.TargetHardwareAddress; arpk.target_ip = arpPacket.TargetProtocolAddress; arpk.adata = Hexdata(arpPacket); // данные пакета string data = HexToAscii(arpPacket); _dispatcher.BeginInvoke(new ThreadStart(delegate { Col.Add(new MyTable { Number = num, Time = StrTime, Src = arpk.sender_ip.ToString(), Dst = arpk.target_ip.ToString(), Protocol = "ARP", Length = len, Info = Convert.ToString(data) }); arpk.pos = num; ArpCol.Add(arpk); num++; })); } if (icmpPacket != null) { IPPacket ipPacket = (IPPacket)icmpPacket.ParentPacket; Icmp icmpk; icmpk.type = icmpPacket.TypeCode.ToString(); icmpk.chksum = icmpPacket.Checksum; icmpk.seq = icmpPacket.Sequence; icmpk.icdata = Hexdata(icmpPacket); // данные пакета string data = ""; for (int i = 0; i < icmpPacket.Data.Count(); i++) { data += icmpPacket.Data[i]; } _dispatcher.BeginInvoke(new ThreadStart(delegate { Col.Add(new MyTable { Number = num, Time = StrTime, Src = ipPacket.SourceAddress.ToString(), Dst = ipPacket.DestinationAddress.ToString(), Protocol = "ICMPv4", Length = len, Info = Convert.ToString(data) }); icmpk.pos = num; IcmpCol.Add(icmpk); num++; })); } if (igmpPacket != null) { IPPacket ipPacket = (IPPacket)igmpPacket.ParentPacket; Igmp igmpk; igmpk.type = igmpPacket.Type.ToString(); igmpk.max_resp_time = igmpPacket.MaxResponseTime.ToString(); igmpk.chksum = igmpPacket.Checksum; igmpk.group_addr = igmpPacket.GroupAddress.ToString(); igmpk.igdata = Hexdata(igmpPacket); // данные пакета string data = HexToAscii(igmpPacket); _dispatcher.BeginInvoke(new ThreadStart(delegate { Col.Add(new MyTable { Number = num, Time = StrTime, Src = ipPacket.SourceAddress.ToString(), Dst = ipPacket.DestinationAddress.ToString(), Protocol = "IGMPv2", Length = len, Info = Convert.ToString(data) }); igmpk.pos = num; IgmpCol.Add(igmpk); num++; })); } }