예제 #1
0
        private void sniffer_loop()
        {
            Sniffer.sniffer_set_inteface(if_name);
            var data   = new SnifferData();
            var result = 5;
            int packet = 0;

            while (true)
            {
                if (sniffer_running)
                {
                    result = Sniffer.sniffer_get(data);
                    if (result != 5)
                    {
                        packet++;
                        AddUpdatePacketNumber(packet);
                    }
                    if (result == 0)
                    {
                        add_connection(data);
                        //AddText("\n" + blabla + "\n");
                    }
                }
                else
                {
                    Thread.Sleep(10);
                }
            }
        }
예제 #2
0
        public void add_data(SnifferData snifferData)
        {
            byte[] payload = Sniffer.get_data_from_snifferdata(snifferData);
            //string blabla = Encoding.ASCII.GetString(payload);
            string blabla = Encoding.UTF8.GetString(payload);

            blabla = Regex.Replace(blabla, @"[^\u0000-\u007F]+", ".");
            conversation.Add(new Tuple <string, bool>(blabla, direction(snifferData)));
        }
예제 #3
0
 public Connection(SnifferData snifferData)
 {
     conversation = new List <Tuple <string, bool> >();
     src          = snifferData.src;
     dst          = snifferData.dst;
     src_port     = snifferData.src_port;
     dst_port     = snifferData.dst_port;
     add_data(snifferData);
 }
예제 #4
0
 public static byte[] get_data_from_snifferdata(SnifferData snifferData)
 {
     byte[] data = new byte[snifferData.len];
     if (snifferData.len != 0 && snifferData.data != 0)
     {
         Marshal.Copy((IntPtr)snifferData.data, data, 0, snifferData.len);
     }
     return(data);
 }
예제 #5
0
 public bool is_connection(SnifferData snifferData)
 {
     return((src.SequenceEqual(snifferData.src) &&
             dst.SequenceEqual(snifferData.dst) &&
             src_port == snifferData.src_port &&
             dst_port == snifferData.dst_port) ||
            (src.SequenceEqual(snifferData.dst) &&
             dst.SequenceEqual(snifferData.src) &&
             src_port == snifferData.dst_port &&
             dst_port == snifferData.src_port));
 }
예제 #6
0
 private void add_connection(SnifferData data)
 {
     foreach (var conn in connections)
     {
         if (conn.is_connection(data))
         {
             conn.add_data(data);
             return;
         }
     }
     connections.Add(new Connection(data));
 }
예제 #7
0
 private bool direction(SnifferData snifferData)
 {
     return(src.SequenceEqual(snifferData.src) && src_port == snifferData.src_port);
 }
예제 #8
0
 public static extern int sniffer_get(
     [In, Out, MarshalAs(UnmanagedType.LPStruct)] SnifferData data);