Beispiel #1
0
        public static bool isLAN(IPAddress ip)
        {
            if (_SegIPList_LAN == null)
            {
                _SegIPList_LAN = new SegmentIPOrderList();
                string[] netmasks = new string[]
                {
                    "0.0.0.0/8",
                    "10.0.0.0/8",
                    //"100.64.0.0/10", //部分地区运营商貌似在使用这个,这个可能不安全
                    "127.0.0.0/8",
                    "169.254.0.0/16",
                    "172.16.0.0/12",
                    //"192.0.0.0/24",
                    //"192.0.2.0/24",
                    "192.168.0.0/16",
                    //"198.18.0.0/15",
                    //"198.51.100.0/24",
                    //"203.0.113.0/24",
                };
                netmasks.ToList().ForEach(s => _SegIPList_LAN.Add(new SegmentIP(s)));
            }
            var rst = _SegIPList_LAN.IsInList(ip);

            return(rst);
        }
        public void ReloadIPRange()
        {
            _rangeSet = new SegmentIPOrderList();
            _rangeSet.LoadChinaIP();

            _rangeSet.IsReverse = (_config.proxyRuleMode == (int)ProxyRuleMode.BypassLanAndNotChina);
        }
Beispiel #3
0
 public void Start(Configuration config, SegmentIPOrderList IPRange, byte[] firstPacket, int length, Socket socket, string local_sendback_protocol, bool proxy)
 {
     _IPRange                       = IPRange;
     _firstPacket                   = firstPacket;
     _firstPacketLength             = length;
     _local                         = new ProxySocketTunLocal(socket);
     _local.local_sendback_protocol = local_sendback_protocol;
     _config                        = config;
     _local_proxy                   = proxy;
     Connect();
 }
Beispiel #4
0
        private void Dispose()
        {
            _transfer = null;
            _IPRange  = null;

            _firstPacket   = null;
            _connection    = null;
            _connectionUDP = null;

            _connetionRecvBuffer    = null;
            _remoteHeaderSendBuffer = null;

            httpProxyState = null;
        }
Beispiel #5
0
        public ProxyAuthHandler(Configuration config, ServerTransferTotal transfer, SegmentIPOrderList IPRange, byte[] firstPacket, int length, Socket socket)
        {
            int local_port = ((IPEndPoint)socket.LocalEndPoint).Port;

            _config            = config;
            _transfer          = transfer;
            _IPRange           = IPRange;
            _firstPacket       = firstPacket;
            _firstPacketLength = length;
            _connection        = socket;
            socket.NoDelay     = true;

            if (_config.GetPortMapCache().ContainsKey(local_port) && _config.GetPortMapCache()[local_port].type == PortMapType.Forward)
            {
                Connect();
            }
            else
            {
                HandshakeReceive();
            }
        }
Beispiel #6
0
        public void TestIPRangeQuery_new()
        {
            SegmentIPOrderList iprs = new SegmentIPOrderList();

            iprs.LoadChinaIP();

            Stopwatch sw = new Stopwatch();

            sw.Start();
            for (int i = 0; i < 100000; i++)
            {
                {
                    var rst = iprs.IsInList(IPAddress.Parse("203.57.200.1"));
                    Assert.IsTrue(rst);
                }
                {
                    var rst = iprs.IsInList(IPAddress.Parse("202.0.184.1"));
                    Assert.IsFalse(rst);
                }
            }
            sw.Stop();
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
        }
Beispiel #7
0
 public Socks5Forwarder(Configuration config, SegmentIPOrderList IPRange)
 {
     _config  = config;
     _IPRange = IPRange;
 }