Пример #1
0
        public Capture(int deviceIndex, string serverAddress, Parse parse)
        {
            ServerAddress = IPAddress.Parse(serverAddress);
            Parse = parse;

            var device = CaptureDeviceList.Instance[deviceIndex];
            device.Open(DeviceMode.Normal, 16);
            device.Filter = String.Format("host {0} and tcp", ServerAddress);

            Console.WriteLine("<watching on {0}>", ServerAddress);

            Reset();
            var thread = new Thread(ProcessThread);
            thread.Start();

            device.OnPacketArrival += new PacketArrivalEventHandler(device_PcapOnPacketArrival);

            device.Capture();

            // not sure how we'd get here but clean up anyway
            Terminate = true;
            thread.Join();
            device.Close();
        }
Пример #2
0
        static void Main(string[] args)
        {
            var devices = CaptureDeviceList.Instance;
            if (devices.Count < 1) {
                Console.WriteLine("No capturable devices found on this machine.");
                return;
            }

            int num = 0;
            if (args.Length > 0) int.TryParse(args[0], out num);

            if (num < 1 || num > devices.Count) {
                Console.WriteLine();
                Console.WriteLine("Usage: {0} <device #> <IP>", Process.GetCurrentProcess().ProcessName);
                Console.WriteLine();
                Console.WriteLine("Available devices:");
                ICaptureDevice dev;
                for (int i = 0; i < devices.Count; i++) {
                    dev = devices[i];
                    Console.Write("  {0}. {1}", i + 1, dev.Name);
                    if (dev.Description.Length > 0) Console.Write(" ({0})", dev.Description);
                    Console.WriteLine();
                }
                Console.WriteLine();
                Console.WriteLine("Server IPs:");
                Console.WriteLine("  Ascension Valley : 208.67.49.84");
                Console.WriteLine("  Celestial Hills  : 208.67.49.68");
                Console.WriteLine("  Lake of Tears    : 208.67.49.52");
                Console.WriteLine("  Mount Tyrannas   : 208.67.49.92");
                Console.WriteLine("  Tempest Reach    : 208.67.49.28");
                Console.WriteLine("  Valley of Titans : 208.67.49.100");
                Console.WriteLine();
                return;
            }

            var parse = new Parse();

            Console.WriteLine();
            Console.WriteLine("Device : {0}", devices[num - 1].Name);
            Console.WriteLine("IP     : {0}", "208.67.49.68");
            Console.WriteLine();

            Console.WriteLine("loading plugins...");
            var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\plugins";
            var plugins = Directory.EnumerateFiles(directory, "*.dll", SearchOption.AllDirectories);
            foreach (string file in plugins) {
                var plugin = Assembly.LoadFrom(file);
                foreach (Type type in plugin.GetTypes()) {
                    if (type.GetInterface("TeraWatcherAPI.IPlugin") != null) {
                        var module = plugin.CreateInstance(type.FullName) as TeraWatcherAPI.IPlugin;
                        try {
                            module.Load(parse);
                            Console.WriteLine("- successfully loaded {0}", type.FullName);
                        } catch (Exception e) {
                            Console.WriteLine("- failed to load {0} ({1})", type.FullName, Path.GetFileName(file));
                            Console.WriteLine(e);
                        }
                    }
                }
            }
            Console.WriteLine();

            var capture = new Capture(num - 1, "208.67.49.68", parse);

            return;
        }