Exemplo n.º 1
0
        static int Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Usage:");
                Console.WriteLine("    BroPing host:port");
                return(1);
            }

            try
            {
                string hostName = args[0];

                Console.WriteLine("Attempting to establish Bro connection to \"{0}\"...", hostName);

                // Create the connection object
                using (BroConnection connection = new BroConnection(hostName))
                {
                    // Register to receive the pong event
                    connection.RegisterForEvent("pong", e =>
                    {
                        BroValue[] values = e.Parameters;
                        DateTime src_time = values[0];
                        DateTime dst_time = values[1];

                        Console.WriteLine("pong event from {0}: seq={1}, time={2}/{3} s",
                                          hostName,
                                          values[2],
                                          (dst_time - src_time).TotalSeconds,
                                          (BroTime.Now - src_time).TotalSeconds);
                    });

                    connection.Connect();

                    Console.WriteLine("Bro connection established. Starting ping cycle, press any key to cancel...");

                    int seq = 0;

                    while (!Console.KeyAvailable)
                    {
                        // Send ping
                        connection.SendEvent("ping", BroTime.Now, new BroValue(seq++, BroType.Count));

                        // Process any received responses
                        connection.ProcessInput();

                        // Wait one second between pings
                        Thread.Sleep(1000);
                    }
                }

                return(0);
            }
            catch (Exception ex)
            {
                Console.Write("Exception: {0}{1}", ex.Message, Environment.NewLine);
                return(1);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            using (BroConnection connection = new BroConnection("bro.yourorg.com:1234"))
            {
                // Establish event handler for received Bro events
                connection.ReceivedEvent += connection_ReceivedEvent;

                // Register for event "foo"
                connection.RegisterForEvent("foo");

                // Connect to remote Bro
                connection.Connect();

                Console.WriteLine("Peer class = " + connection.PeerClass);

                // Create a new event
                BroEvent bar = new BroEvent("bar");

                bar.AddParameter("Text parameter");
                bar.AddParameter(true);
                bar.AddParameter("192.168.1.1", BroType.IpAddr);
                bar.AddParameter(new BroPort(80, ProtocolType.Tcp));
                bar.AddParameter(2, BroType.Enum, "transport_proto");
                bar.AddParameter(BroTime.Now);

                // Send the event
                bool result = connection.SendEvent(bar);
                Console.WriteLine("Event \"bar\" {0}", result ? "was sent or queued for later delivery" : "failed to send or queue");

                // Process any incoming events...
                connection.ProcessInput();

                Console.ReadLine();

                // Unregister from event "foo"
                connection.UnregisterForEvent("foo");
            }
        }