Exemplo n.º 1
0
        public TeraSniffer(IpSniffer ipSniffer, ServerDatabase servers)
        {
            _serversByIp = servers.GetServersByIp();

            if (ipSniffer == null)
            {
                var netmasks = _serversByIp.Keys.Select(s => string.Join(".", s.Split('.').Take(3)) + ".0/24").Distinct().ToArray();

                string filter = string.Join(" or ", netmasks.Select(x => $"(net {x})"));
                filter = "tcp and (" + filter + ")";

                try
                {
                    ipSniffer = new IpSnifferWinPcap(filter);
                }
                catch
                {
                    ipSniffer = new IpSnifferRawSocketMultipleInterfaces();
                }
            }

            _ipSniffer = ipSniffer;

            var tcpSniffer = new TcpSniffer(_ipSniffer);
            tcpSniffer.NewConnection += HandleNewConnection;
        }
Exemplo n.º 2
0
        private TeraSniffer()
        {
            var servers = BasicTeraData.Instance.Servers;
            _serversByIp = servers.GetServersByIp();

            if (BasicTeraData.Instance.WindowData.Winpcap)
            {
                var netmasks =
                    _serversByIp.Keys.Select(s => string.Join(".", s.Split('.').Take(3)) + ".0/24").Distinct().ToArray();

                var filter = string.Join(" or ", netmasks.Select(x => $"(net {x})"));
                filter = "tcp and (" + filter + ")";

                try //fallback to raw sockets if no winpcap available
                {
                    _ipSniffer = new IpSnifferWinPcap(filter);
                    (_ipSniffer as IpSnifferWinPcap).Warning += OnWarning;
                }
                catch
                {
                    _ipSniffer = new IpSnifferRawSocketMultipleInterfaces();
                }
            }
            else
            {
                _ipSniffer = new IpSnifferRawSocketMultipleInterfaces();
            }

            var tcpSniffer = new TcpSniffer(_ipSniffer);
            tcpSniffer.NewConnection += HandleNewConnection;
        }
Exemplo n.º 3
0
        public TeraSniffer(IEnumerable<Server> servers)
        {
            _serversByIp = servers.ToDictionary(x => x.Ip);
            var netmasks =
                _serversByIp.Keys.Select(s => string.Join(".", s.Split('.').Take(3)) + ".0/24").Distinct().ToArray();
            var filter = string.Join(" or ", netmasks.Select(x => $"(net {x})"));
            filter = "tcp and (" + filter + ")";

            _ipSniffer = new IpSniffer(filter);
            var tcpSniffer = new TcpSniffer(_ipSniffer);
            tcpSniffer.NewConnection += HandleNewConnection;
        }
Exemplo n.º 4
0
        //internal struct QPacket
        //{
        //    internal TcpConnection Connection;
        //    internal uint SequenceNumber;
        //    internal ArraySegment<byte> Packet;

        //    internal QPacket(TcpConnection connection, uint sequenceNumber, ArraySegment<byte> packet)
        //    {
        //        Connection = connection;
        //        SequenceNumber = sequenceNumber;
        //        var data = new byte[packet.Count];
        //        Array.Copy(packet.Array, packet.Offset, data, 0, packet.Count);
        //        Packet = new ArraySegment<byte>(data,0,data.Length);
        //    }
        //}
        //private ConcurrentQueue<QPacket> _buffer = new ConcurrentQueue<QPacket>();
        public TcpSniffer(IpSniffer ipSniffer)
        {
            ipSniffer.PacketReceived += Receive;
            SnifferType = ipSniffer.GetType().FullName;
            //Task.Run(()=>ParsePacketsLoop());
        }
Exemplo n.º 5
0
 public TcpSniffer(IpSniffer ipSniffer)
 {
     ipSniffer.PacketReceived += Receive;
 }
Exemplo n.º 6
0
 public TcpSniffer(IpSniffer ipSniffer)
 {
     ipSniffer.PacketReceived += Receive;
 }
Exemplo n.º 7
0
 //internal struct QPacket
 //{
 //    internal TcpConnection Connection;
 //    internal uint SequenceNumber;
 //    internal ArraySegment<byte> Packet;
 //    internal QPacket(TcpConnection connection, uint sequenceNumber, ArraySegment<byte> packet)
 //    {
 //        Connection = connection;
 //        SequenceNumber = sequenceNumber;
 //        var data = new byte[packet.Count];
 //        Array.Copy(packet.Array, packet.Offset, data, 0, packet.Count);
 //        Packet = new ArraySegment<byte>(data,0,data.Length);
 //    }
 //}
 //private ConcurrentQueue<QPacket> _buffer = new ConcurrentQueue<QPacket>();
 public TcpSniffer(IpSniffer ipSniffer)
 {
     ipSniffer.PacketReceived += Receive;
     SnifferType = ipSniffer.GetType().FullName;
     //Task.Run(()=>ParsePacketsLoop());
 }