Пример #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;
        }
Пример #2
0
        public TeraSniffer(IEnumerable<string> serverIps)
        {
            _interestingIps = new HashSet<string>(serverIps);
            var netmasks =
                _interestingIps.Select(s => string.Join(".", s.Split('.').Take(3)) + ".0/24").Distinct().ToArray();
            string filter = string.Join(" or ", netmasks.Select(x => string.Format("(net {0})", x)));
            filter = "tcp and (" + filter + ")";

            _ipSniffer = new IpSnifferWinPcap(filter);
            var tcpSniffer = new TcpSniffer(_ipSniffer);
            tcpSniffer.NewConnection += HandleNewConnection;
        }
Пример #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();
            string filter = string.Join(" or ", netmasks.Select(x => string.Format("(net {0})", x)));
            filter = "tcp and (" + filter + ")";

            _ipSniffer = new IpSnifferWinPcap(filter);
            _ipSniffer.Warning += OnWarning;
            var tcpSniffer = new TcpSniffer(_ipSniffer);
            tcpSniffer.NewConnection += HandleNewConnection;
        }
Пример #4
0
        public TeraSniffer(IpSniffer ipSniffer, IEnumerable<Server> servers)
        {
            _serversByIp = servers.ToDictionary(x => x.Ip);

            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 + ")";

                ipSniffer = new IpSnifferWinPcap(filter);
            }

            _ipSniffer = ipSniffer;

            var tcpSniffer = new TcpSniffer(_ipSniffer);
            tcpSniffer.NewConnection += HandleNewConnection;
        }