Exemple #1
0
        private void forwadtoclient(Client sender, byte[] buffer)
        {
            PManager = new PackManager(ClientForm);
            string content_hex = string.Empty;
            int    huit_bytes  = 0;

            foreach (byte b in buffer)
            {
                content_hex += b.ToString("X2") + " ";
                huit_bytes++;
            }
            PManager.ParsePacket(buffer);
            ClientForm.AddItem(true, PManager.packet_id, idNames.GetClasseName(PManager.packet_id), PManager.packet_lenght, PManager.packet_content);
            PManager.ParsePacket(buffer);
            sender.associated.send(buffer);
        }
Exemple #2
0
        private void forwardtoserver(Client sender, byte[] buffer)
        {
            PManager = new PackManager(ClientForm);
            string content_hex = string.Empty;
            int    huit_bytes  = 0;

            foreach (byte b in buffer)
            {
                content_hex += b.ToString("X2") + " ";
                huit_bytes++;
            }
            PManager.ParsePacket(buffer);
            ClientForm.AddItem(false, PManager.packet_id, idNames.GetClasseName(PManager.packet_id), PManager.packet_lenght, PManager.packet_content);
            //ClientForm.WriteLogClient(content_hex + "\tASCII = " + Encoding.ASCII.GetString(buffer));
            sender.associated.send(buffer);
        }
        public Capture()
        {
            // Retrieve the device list from the local machine
            IList <LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;

            if (allDevices.Count == 0)
            {
                Console.WriteLine("No interfaces found! Make sure WinPcap is installed.");
                return;
            }

            // Print the list
            for (int i = 0; i != allDevices.Count; ++i)
            {
                LivePacketDevice device = allDevices[i];
                Console.Write((i + 1) + ". " + device.Name);
                if (device.Description != null)
                {
                    Console.WriteLine(" (" + device.Description + ")");
                }
                else
                {
                    Console.WriteLine(" (No description available)");
                }
            }

            int deviceIndex = 0;

            do
            {
                Console.WriteLine("Enter the interface number (1-" + allDevices.Count + "):");
                string deviceIndexString = Console.ReadLine();
                if (!int.TryParse(deviceIndexString, out deviceIndex) ||
                    deviceIndex < 1 || deviceIndex > allDevices.Count)
                {
                    deviceIndex = 0;
                }
            } while (deviceIndex == 0);

            // Take the selected adapter
            PacketDevice selectedDevice = allDevices[deviceIndex - 1];

            // Open the device
            using (PacketCommunicator communicator =
                       selectedDevice.Open(2000,                                                                                                                            // portion of the packet to capture
                                           PacketDeviceOpenAttributes.Promiscuous | PacketDeviceOpenAttributes.NoCaptureLocal | PacketDeviceOpenAttributes.NoCaptureRemote, // promiscuous mode
                                           100))                                                                                                                            // read timeout
            {
                Console.WriteLine("Listening on " + selectedDevice.Description + "...");

                // start the capture
                communicator.SetFilter("net 213.248.126.0 mask 255.255.255.0");
                packManager = new PackManager();

                /*Thread thread = new Thread(new ThreadStart(packManager.process));
                 * thread.Start();*/
                //packetProcesser = new PacketProcesser();
                //Thread thread = new Thread(new ThreadStart(packetProcesser.process));
                //thread.Start();
                //communicator.ReceivePackets(0, PacketHandler);
                // Retrieve the packets
                Packet packet;

                do
                {
                    PacketCommunicatorReceiveResult result = communicator.ReceivePacket(out packet);
                    switch (result)
                    {
                    case PacketCommunicatorReceiveResult.Timeout:
                        // Timeout elapsed
                        continue;

                    case PacketCommunicatorReceiveResult.Ok:
                        packManager.ParsePacket(getData(packet));
                        //packetProcesser.addPacket(packet);
                        break;

                    default:
                        throw new InvalidOperationException("The result " + result + " shoudl never be reached here");
                    }
                } while (true);
            }
        }