예제 #1
0
        public Sniffer(string target, string mac, string gatewaymac, string gatewayip, Loading loading)
        {
            InitializeComponent();

            var materialSkinManager = MaterialSkinManager.Instance;

            materialSkinManager.AddFormToManage(this);
            gatewayIP  = gatewayip;
            gatewayMAC = gatewaymac;
            GatewayMAC = PhysicalAddress.Parse(gatewaymac.Replace(":", ""));
            TargetMAC  = PhysicalAddress.Parse(mac.Replace(":", ""));
            TargetIP   = IPAddress.Parse(target);

            olvColumn7.AspectGetter = delegate(object rowObject)
            {
                try
                {
                    AcceptedPacket packet = rowObject as AcceptedPacket;
                    if ((packet != null && (string.IsNullOrEmpty(packet.Host) && packet.Source.ToString() == Target) || packet.Host == "Not found"))//null reference on sniffer close
                    {
                        return("Resolve");
                    }

                    return(null);
                }
                catch (Exception)
                {
                }
                return(null);
            };


            textOverlay            = this.materialListView1.EmptyListMsgOverlay as TextOverlay;
            menu                   = new ContextMenu(new MenuItem[] { new MenuItem("Show Packet", ShowPacket), });
            Target                 = target;
            targetmac              = mac;
            olvColumn1.ImageGetter = delegate(object rowObject)
            {
                var Packet = rowObject as AcceptedPacket;
                try
                {
                    if (Packet.Source.ToString() == Target)
                    {
                        return("request");
                    }
                    else
                    {
                        return("response");
                    }
                }
                catch (Exception)
                {
                    return("");
                }
            };
        }
예제 #2
0
        public Sniffer(Device device)
        {
            InitializeComponent();

            var materialSkinManager = MaterialSkinManager.Instance;

            materialSkinManager.AddFormToManage(this);

            this.Device = device;

            #region List Configuration

            //Set empty list overlay
            ListOverlay = this.materialListView1.EmptyListMsgOverlay as TextOverlay;

            //A context menu to be added to list items on every right click and removed on empty clicks
            PacketMenu = new ContextMenu(new MenuItem[] { new MenuItem("Show Packet", ShowPacket), });

            //This delegate decides if the list item has a resolve button
            olvColumn7.AspectGetter = delegate(object rowObject)
            {
                try
                {
                    AcceptedPacket packet = rowObject as AcceptedPacket;

                    if (packet == null)
                    {
                        return(null);
                    }

                    if (string.IsNullOrEmpty(packet.Host) && packet.Source.Equals(device.IP) || packet.Host == "Not found")
                    {
                        return("Resolve");
                    }
                }
                catch { }

                return(null);
            };

            //Select row icon based on the packet type (Request or Response)
            olvColumn1.ImageGetter = delegate(object rowObject)
            {
                AcceptedPacket Packet = rowObject as AcceptedPacket;
                if (Packet == null)
                {
                    return(default);
예제 #3
0
        private void StartSniffer()
        {
            try
            {
                RawCapture rawCapture;
                do
                {
                    if ((rawCapture = capturedevice.GetNextPacket()) != null)
                    {
                        EthernetPacket Packet = PacketDotNet.Packet.ParsePacket(rawCapture.LinkLayerType, rawCapture.Data) as EthernetPacket;
                        if (Packet == null)
                        {
                            return;
                        }

                        AcceptedPacket acPacket = new AcceptedPacket();
                        acPacket.Packet = Packet;

                        if (Packet.SourceHwAddress.Equals(TargetMAC))
                        {
                            if (acPacket.TCPPacket != null)
                            {
                                materialListView1.BeginInvoke(new Action(() =>
                                {
                                    materialListView1.AddObject(acPacket);

                                    if (materialListView1.Items.Count > 15 && !ResizeDone)
                                    {
                                        olvColumn8.MaximumWidth = 65;
                                        olvColumn8.MinimumWidth = 65;
                                        olvColumn8.Width        = 65;
                                        ResizeDone = true;
                                    }

                                    ListofAcceptedPackets.Add(acPacket);
                                }));
                            }
                        }

                        else if (Packet.SourceHwAddress.Equals(GatewayMAC))
                        {
                            if (Properties.Settings.Default.PacketDirection == "Inbound")
                            {
                                IPv4Packet IPV4 = Packet.Extract(typeof(IPv4Packet)) as IPv4Packet;

                                if (IPV4.DestinationAddress.Equals(TargetIP))
                                {
                                    if (acPacket.TCPPacket != null)
                                    {
                                        materialListView1.BeginInvoke(new Action(() =>
                                        {
                                            materialListView1.AddObject(acPacket);

                                            if (materialListView1.Items.Count > 15 && !ResizeDone)
                                            {
                                                olvColumn8.MaximumWidth = 65;
                                                olvColumn8.MinimumWidth = 65;
                                                olvColumn8.Width        = 65;
                                                ResizeDone = true;
                                            }

                                            ListofAcceptedPackets.Add(acPacket);
                                        }));
                                    }
                                }
                            }
                        }
                    }
                } while (snifferStarted);
            }
            catch (Exception)
            {
            }
        }
예제 #4
0
        private void CapturedeviceOnOnPacketArrival(object sender, CaptureEventArgs e)
        {
            new Thread(() =>
            {
                try
                {
                    if (StopFlag)
                    {
                        return;
                    }

                    EthernetPacket Packet = PacketDotNet.Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data) as EthernetPacket;
                    if (Packet == null)
                    {
                        return;
                    }

                    AcceptedPacket acPacket = new AcceptedPacket();
                    acPacket.Packet         = Packet;

                    if (Packet.SourceHwAddress.Equals(TargetMAC))
                    {
                        if (acPacket.TCPPacket != null)
                        {
                            materialListView1.BeginInvoke(new Action(() =>
                            {
                                materialListView1.AddObject(acPacket);

                                if (materialListView1.Items.Count > 15 && !ResizeDone)
                                {
                                    olvColumn8.MaximumWidth = 65;
                                    olvColumn8.MinimumWidth = 65;
                                    olvColumn8.Width        = 65;
                                    ResizeDone = true;
                                }

                                ListofAcceptedPackets.Add(acPacket);
                            }));
                        }
                    }

                    else if (Packet.SourceHwAddress.Equals(GatewayMAC))
                    {
                        if (Properties.Settings.Default.PacketDirection == "Inbound")
                        {
                            IPv4Packet IPV4 = Packet.Extract(typeof(IPv4Packet)) as IPv4Packet;

                            if (IPV4.DestinationAddress.Equals(TargetIP))
                            {
                                if (acPacket.TCPPacket != null)
                                {
                                    materialListView1.BeginInvoke(new Action(() =>
                                    {
                                        materialListView1.AddObject(acPacket);

                                        if (materialListView1.Items.Count > 15 && !ResizeDone)
                                        {
                                            olvColumn8.MaximumWidth = 65;
                                            olvColumn8.MinimumWidth = 65;
                                            olvColumn8.Width        = 65;
                                            ResizeDone = true;
                                        }

                                        ListofAcceptedPackets.Add(acPacket);
                                    }));
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                }
            }).Start();
        }