public bool IsProxyAlive(SocksProxy.Proxy proxy, int timeout = 1000) { try { Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IAsyncResult result = clientSocket.BeginConnect(proxy.ip, proxy.port, null, null); result.AsyncWaitHandle.WaitOne(timeout, true); clientSocket.ReceiveTimeout = timeout; clientSocket.SendTimeout = timeout; if (clientSocket.Connected) { if (proxy.proxyType == SocksProxy.ProxyType.SOCKS5) { // socks5, no authentication required byte[] handshake = { 5, 1, 0 }; byte[] buffer = new byte[32]; clientSocket.Send(handshake); clientSocket.Receive(buffer); if (buffer[0] == 5 && buffer[1] == 0) { clientSocket.Close(); return(true); } } else { if (google == null) { google = Dns.GetHostEntry("www.google.com"); } //SOCKS4 byte[] handshake = { 4, 1, 0, 80, 0, 0, 0, 0, (byte)'C', (byte)'H', (byte)'A', (byte)'T', (byte)'A', (byte)'N', (byte)'G', (byte)'O', 0 }; int _ip = BitConverter.ToInt32(google.AddressList[0].GetAddressBytes(), 0); byte[] ip = BitConverter.GetBytes(_ip); if (BitConverter.IsLittleEndian) { Array.Reverse(ip); } handshake[4] = ip[0]; handshake[5] = ip[1]; handshake[6] = ip[2]; handshake[7] = ip[3]; clientSocket.Send(handshake); byte[] buffer = new byte[32]; clientSocket.Receive(buffer); if (buffer[0] == 4 && buffer[1] == 0x5A) { clientSocket.Close(); return(true); } } } clientSocket.Close(); } catch (Exception) { } return(false); }
public Post(string _host, SocksProxy.Proxy _proxy, onCompletion _onCompletionCallback) : base(_proxy) { host = _host; onCompletionCallback = _onCompletionCallback; // internal onReceiveCallback = myOnReceiveCallback; onConnectCallback = myOnConnectCallback; onCloseCallback = myOnCloseCallback; }
public ChatangoAccount(string username, string password, SocksProxy.Proxy proxy) { this.proxy = proxy; // assume the account exists this.exists = true; this.username = username; this.password = password; if (username == null) { this.password = GeneratePassword(); this.username = GenerateUsername(); this.exists = false; } }
public Proxy(SocksProxy.Proxy _proxy) { proxy = _proxy; isConnected = false; }