Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var proxyServer = new FirewallTcpProxyServer(IPEndPoint.Parse("192.168.31.1:80"));

            proxyServer.OnConnected += (session) =>
            {
                Console.WriteLine("New Connection");
            };
            proxyServer.Start().Wait();

            Console.WriteLine($"Port: {proxyServer.ListenPort}");

            proxyServer.UpdateAllowCidrList(new CIDRNotation[] { CIDRNotation.Parse("0.0.0.0/0") });

            Console.Read();
        }
Ejemplo n.º 2
0
        private async Task StartProxyServer(Service service)
        {
            if (!service.Enabled)
            {
                return;
            }

            var serverId = await GetProxyServerId(service.Id);

            if (serverId.HasValue)
            {
                return;
            }

            var targets = await ListServiceForwardTarget(service.Id);

            targets = targets.Where(x => x.Enabled);

            if (targets.Count() > 1)
            {
                throw new NotImplementedException();
            }

            if (!targets.Any())
            {
                return;
            }

            var target = targets.First();

            IProxyServer proxyServer;

            switch (service.Protocol)
            {
            case ServiceProtocols.TCP:
                proxyServer = new FirewallTcpProxyServer(IPEndPoint.Parse(target.IPAddress + ":" + target.Port), service.Port);
                break;

            default:
                throw new NotImplementedException();
                break;
            }

            _serverIdMap[service.Id] = proxyServer.Id;
            proxyServer.OnConnected += (sender) =>
            {
                Console.WriteLine($"Connect: {sender.ClientEndPoint.ToString()}");
            };
            proxyServer.OnDisconnected += (sender) =>
            {
                Console.WriteLine($"Disconnect: {sender.ClientEndPoint.ToString()}");
            };

            if (proxyServer is FirewallTcpProxyServer fwProxyServer)
            {
                var rules = await ListServiceAllowRule(service.Id);

                await fwProxyServer.UpdateAllowCidrList(await GetServiceAllowRuleCIDRNotation(service.Id, target.Id));
            }

            await _proxyServerHub.AddProxyServer(proxyServer);
        }