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); } } }
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))); }
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); }
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); }
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)); }
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)); }
private bool direction(SnifferData snifferData) { return(src.SequenceEqual(snifferData.src) && src_port == snifferData.src_port); }
public static extern int sniffer_get( [In, Out, MarshalAs(UnmanagedType.LPStruct)] SnifferData data);