예제 #1
0
        static void Main(string[] args)
        {
            var devices = CaptureDeviceList.Instance;

            if (devices.Count < 1)
            {
                Console.WriteLine("No device found on this machine");
                return;
            }

            Console.WriteLine("The following devices are available on this machine:");
            Console.WriteLine("----------------------------------------------------");
            Console.WriteLine();

            int i = 0;

            foreach (var dev in devices)
            {
                Console.WriteLine("{0}) {1} {2}", i, dev.Name, dev.Description);
                i++;
            }

            Console.WriteLine();
            Console.Write("-- Please choose a device to capture: ");
            i = int.Parse(Console.ReadLine());

            var device = devices[i];

            device.OnPacketArrival +=
                device_OnPacketArrival;

            int readTimeoutMilliseconds = 1000;

            device.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);

            LocalPhysicalAddress = device.MacAddress;

            string filter = "ip and tcp";

            device.Filter = filter;

            Console.WriteLine();
            Console.WriteLine("-- The following tcpdump filter will be applied: \"{0}\"", filter);

            if (LoginServerIP == null)
            {
                Console.Write("-- Please input target LoginServer IP: ");
                LoginServerIP = IPAddress.Parse(Console.ReadLine());
                Console.WriteLine();
            }
            if (LoginServerPort == 0)
            {
                Console.Write("-- Please input target LoginServer Port: ");
                LoginServerPort = int.Parse(Console.ReadLine());
                Console.WriteLine();
            }
            BreakIpAddresses.Add(LoginServerIP);

            Console.WriteLine
                ("-- Listening on {0}, hit 'Ctrl-C' to exit...",
                device.Description);

            device.Capture();
            device.Close();
        }
예제 #2
0
        private static void Main(string[] args)
        {
            var devices = CaptureDeviceList.Instance;

            if (devices.Count < 1)
            {
                Console.WriteLine("No device found on this machine");
                return;
            }

            Console.WriteLine("The following devices are available on this machine:");
            Console.WriteLine("----------------------------------------------------");
            Console.WriteLine();

            var i = 0;

            foreach (var dev in devices)
            {
                Console.WriteLine("{0}) {1} {2}", i, dev.Name, dev.Description);
                i++;
            }

            Console.WriteLine();
            Console.Write("-- Please choose a device to capture: ");
            i = int.Parse(Console.ReadLine());

            var device = devices[i];

            device.OnPacketArrival +=
                device_OnPacketArrival;

            var readTimeoutMilliseconds = 1000;

            device.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);

            var filter = "ip and tcp";

            device.Filter = filter;

            Console.WriteLine();
            Console.WriteLine("-- The following tcpdump filter will be applied: \"{0}\"", filter);

            if (LoginServerIP == null)
            {
                Console.Write("-- Please input target LoginServer IP: ");
                LoginServerIP = IPAddress.Parse(Console.ReadLine());
                Console.WriteLine();
            }

            if (LoginServerPort == 0)
            {
                Console.Write("-- Please input target LoginServer Port: ");
                LoginServerPort = int.Parse(Console.ReadLine());
                Console.WriteLine();
            }

            BreakIpAddresses.Add(LoginServerIP);
            ServerPorts.Add(LoginServerPort);

            Console.WriteLine
                ("-- Listening on {0}, hit 'Ctrl-C' to exit...",
                device.Description);
            var filePath = Path.Combine(LaunchTime.ToString("s").Replace(':', '_'), "PacketFlow.txt");
            var flowFile = new FileInfo(filePath);

            flowFile.Directory?.Create();
            using var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
            using (packerFlowStream = new StreamWriter(fs))
            {
                packerFlowStream.AutoFlush = true;
                device.Capture();
                device.Close();
                packerFlowStream.Flush();
                fs.Flush(true);
            }
        }