//Selection changed @ packetlist private void PacketList_SelectionChanged(object sender, SelectionChangedEventArgs e) { //Remove packetinfo (if there is any) PacketInfo.Items.Clear(); btnStartEdit.IsEnabled = true; //Create virtual packet from existing virtual packet pInfoPacket = new PacketAPI(); pInfoPacket = (PacketAPI)PacketList.SelectedItems[0]; //Show more details about the currently selected packet PacketInfo.Items.Add("Time Of Arrival: " + pInfoPacket.Timestamp); if (pInfoPacket.Http) PacketInfo.Items.Add("Protocol encapsulation: IPV4 / TCP / HTTP"); else if (pInfoPacket.Dns) PacketInfo.Items.Add("Protocol encapsulation: IPV4 / UDP / DNS"); else if (pInfoPacket.Tcp) PacketInfo.Items.Add("Protocol encapsulation: IPV4 / TCP"); else if (pInfoPacket.Udp) PacketInfo.Items.Add("Protocol encapsulation: IPV4 / UDP"); else if (pInfoPacket.Icmp) PacketInfo.Items.Add("Protocol encapsulation: IPV4 / ICMP"); else PacketInfo.Items.Add("Protocol encapsulation: IPV4 / Unknown"); PacketInfo.Items.Add("MAC Source: " + pInfoPacket.MacSource + "\tMAC Destination: " + pInfoPacket.MacDestination); PacketInfo.Items.Add("IP Source: " + pInfoPacket.IpSource + "\t\tIP Destination: " + pInfoPacket.IpDestination); PacketInfo.Items.Add("Length: " + pInfoPacket.Length + "\t\t\tTTL: " + pInfoPacket.Ttl + "\t\t\tID: " + pInfoPacket.Id); PacketInfo.Items.Add("Source Port: " + pInfoPacket.PortSource + "\t\t\tDestination Port: " + pInfoPacket.PortDestination); }
//Add arrived packets to the Observable Collection and update in the list private void UpdatePacketText(PacketAPI packet) { ocPackets.Add(packet); }
//Create a virtual packet from the original packet private void PacketHandler(Packet packet) { //Create virtual packet var ArrivedPacket = new PacketAPI(); //Bind original packet data to virtual packet ArrivedPacket.Timestamp = packet.Timestamp.ToString(); ArrivedPacket.MacSource = packet.Ethernet.Source.ToString(); ArrivedPacket.MacDestination = packet.Ethernet.Destination.ToString(); ArrivedPacket.IpSource = packet.Ethernet.IpV4.Source.ToString(); ArrivedPacket.IpDestination = packet.Ethernet.IpV4.Destination.ToString(); ArrivedPacket.Length = packet.Length; ArrivedPacket.Ttl = packet.Ethernet.IpV4.Ttl; ArrivedPacket.Id = packet.Ethernet.IpV4.Identification; //Find out what protocol the original packet is using and bind as well //(This part is not optimal yet) if (packet.Ethernet.EtherType == EthernetType.IpV4) { ArrivedPacket.Ipv4 = true; ArrivedPacket.Protocol = "IPV4"; if (packet.Ethernet.IpV4.Icmp != null && packet.Ethernet.IpV4.Protocol.ToString() == "InternetControlMessageProtocol") { ArrivedPacket.Icmp = true; ArrivedPacket.Protocol = "ICMP"; } else { ArrivedPacket.Icmp = false; } if (packet.Ethernet.IpV4.Udp != null && packet.Ethernet.IpV4.Protocol.ToString() == "Udp") { ArrivedPacket.Udp = true; ArrivedPacket.Protocol = "UDP"; ArrivedPacket.PortSource = packet.Ethernet.IpV4.Udp.SourcePort; ArrivedPacket.PortDestination = packet.Ethernet.IpV4.Udp.DestinationPort; if (ArrivedPacket.PortDestination == 53 || ArrivedPacket.PortDestination > 1023 || ArrivedPacket.PortSource == 53 || ArrivedPacket.PortSource > 1023) { ArrivedPacket.Dns = true; ArrivedPacket.Protocol = "DNS"; } else { ArrivedPacket.Dns = false; } } else { ArrivedPacket.Udp = false; } if (packet.Ethernet.IpV4.Tcp != null && packet.Ethernet.IpV4.Protocol.ToString() == "Tcp") { ArrivedPacket.Tcp = true; ArrivedPacket.Protocol = "TCP"; ArrivedPacket.PortSource = packet.Ethernet.IpV4.Tcp.SourcePort; ArrivedPacket.PortDestination = packet.Ethernet.IpV4.Tcp.DestinationPort; if (ArrivedPacket.PortDestination == 80 || ArrivedPacket.PortSource == 80) { ArrivedPacket.Http = true; ArrivedPacket.Protocol = "HTTP"; } else { ArrivedPacket.Http = false; } } else { ArrivedPacket.Tcp = false; } } else { ArrivedPacket.Ipv4 = false; } //Check the filter to see which packets are allowed to be shown if (bIcmpCheck && ArrivedPacket.Icmp) Dispatcher.Invoke(new UpdateTextCallback(UpdatePacketText), ArrivedPacket); else if (bUdpCheck && ArrivedPacket.Udp) Dispatcher.Invoke(new UpdateTextCallback(UpdatePacketText), ArrivedPacket); else if (bTcpCheck && ArrivedPacket.Tcp) Dispatcher.Invoke(new UpdateTextCallback(UpdatePacketText), ArrivedPacket); else if (bDnsCheck && ArrivedPacket.Dns) Dispatcher.Invoke(new UpdateTextCallback(UpdatePacketText), ArrivedPacket); else if (bHttpCheck && ArrivedPacket.Http) Dispatcher.Invoke(new UpdateTextCallback(UpdatePacketText), ArrivedPacket); else if (bIPV4Check && ArrivedPacket.Ipv4) Dispatcher.Invoke(new UpdateTextCallback(UpdatePacketText), ArrivedPacket); }