コード例 #1
0
        public Dnss(TUN2Socks tun2socks, int port)
        {
            this.m_iVfptrAddress = BitConverter.ToInt32(IPAddress.Parse("198.18.0.0").GetAddressBytes(), 0);
            this.m_iVfptrAddress = IPAddress.NetworkToHostOrder(this.m_iVfptrAddress);

            this.m_poTUN2Socks = tun2socks ?? throw new ArgumentNullException(nameof(tun2socks));
            this.m_poSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            this.m_poSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            this.m_poSocket.Bind(new IPEndPoint(IPAddress.Any, port));
        }
コード例 #2
0
        protected virtual bool OnRequest(DnsRequest request, EndPoint remoteEP)
        {
            var pac = this.m_poTUN2Socks.GetPAC();
            if (!pac.IsReady())
            {
                return this.SuperiorAcquired(request, (message, response) => this.SendTo(response.ToArray(), remoteEP));
            }
            lock (this.m_poDnsMap)
            {
                this.m_poDnsMap.TryGetValue(request.Domain, out IPAddress address);
                if (address != null)
                {
                    return this.SendTo(this.CreateResponse(request, address).ToArray(), remoteEP);
                }
            }
            return this.SuperiorAcquired(request, (message, response) =>
            {
                string hijacked = string.Empty;
                lock (this.m_poDnsMap)
                {
                    //var addresses = DnsResponse.GetAddresses(response.Answers);
                    //if (!this.IsNotAllowAgent(addresses))
                    {
                        hijacked = "[:hijacked] ";

                        IPAddress address = this.NewVirtualAddress();
                        {
                            this.m_poDnsMap[request.Domain] = address;
                            this.m_poDnsMapFar[address] = request.Domain;
                        }
                        response = this.CreateResponse(request, address);
                    }
                }

                TUN2Socks.PrintTraceLine($"NSLookup[{request.QueryType}, {request.QueryClass}]: {request.Domain} {hijacked}-> {string.Join(" ", DnsResponse.FetchAddresses(response.Answers))}");
                this.SendTo(response.ToArray(), remoteEP);
            });
        }
コード例 #3
0
 public TUN2SocksSocketScheduler(TUN2Socks tun2socks, ILayerLocator locator) : base(locator)
 {
     this.m_tun2socks = tun2socks ?? throw new ArgumentNullException(nameof(tun2socks));
 }
コード例 #4
0
        public Dnss(TUN2Socks tun2socks) : this(tun2socks, Dnss.Port)
        {

        }
コード例 #5
0
ファイル: TUN2Socks.cs プロジェクト: liulilittle/SkylakeNAT
 public TUN2Layer3Locator(TUN2Socks tun2socks, string componentId) : base(componentId)
 {
     this.Sockets = tun2socks.CreateSocketScheduler(this);
 }
コード例 #6
0
 public TUN2SocksSocket(TUN2Socks tun2socks, IPcb pcb) : base(pcb)
 {
     this.m_tun2socks = tun2socks ?? throw new ArgumentNullException(nameof(tun2socks));
 }