示例#1
0
        private void AcceptClientConnection(SISession session, Socks5Server server, int timeout = -1)
        {
            SocksRequest request = server.Accept(timeout);

            if (request.Command != SocksCommand.Connect)
            {
                throw new Socks5Exception("Unexpected SOCKS5 command: " + request.Command);
            }
            if (request.ATyp != ATyp.Domain)
            {
                throw new Socks5Exception("Unexpected ATyp: " + request.ATyp);
            }
            string destination = (string)request.Destination;

            if (this.Sha1(session.Sid + base.im.Jid + session.To) != destination)
            {
                throw new Socks5Exception("Hostname hash mismatch.");
            }
            server.Reply(ReplyStatus.Succeeded, destination, request.Port);
        }
示例#2
0
文件: Socks.cs 项目: cuongnq/Socks5
        public static socks5.Socks.SocksError SendRequest(Socks5Client cli, string ipOrDomain, int port)
        {
            AddressType type;
            IPAddress   ipAddress;

            if (!IPAddress.TryParse(ipOrDomain, out ipAddress))
            {
                //it's a domain. :D (hopefully).
                type = AddressType.Domain;
            }
            else
            {
                type = AddressType.IP;
            }
            SocksRequest sr = new SocksRequest(StreamTypes.Stream, type, ipOrDomain, port);

            //send data.
            byte[] p = sr.GetData(false);
            p[1] = 0x01;
            cli.Client.Send(p);
            byte[] buffer = new byte[512];
            cli.Client.Receive(buffer, 0, buffer.Length);
            return((SocksError)buffer[1]);
        }
 /// <summary>
 /// Override the connection, to do whatever you want with it. Client is a wrapper around a socket.
 /// </summary>
 /// <param name="sr">The original request params.</param>
 /// <returns></returns>
 public abstract Client OnConnectOverride(SocksRequest sr);
示例#4
0
 /// <summary>
 /// Handle request callback.
 /// </summary>
 /// <param name="Request"></param>
 /// <returns>Return true to allow the connection, return false to deny it.</returns>
 public abstract bool OnConnect(SocksRequest Request);