예제 #1
0
파일: WebProxy.cs 프로젝트: QardenEden/Suru
		//sendraw SSL
		public string sendraw (string ipRaw, string portRaw, string payloadRaw, int size, int TimeOut, int retry, bool useSSL) {
			
			IPHostEntry IPHost = Dns.Resolve(ipRaw); 
			string []aliases = IPHost.Aliases; 
			IPAddress[] addr = IPHost.AddressList; 
			IPEndPoint iep ;
			SecureProtocol sp;
			sp=SecureProtocol.Ssl3;
			SecureSocket s=null; 
			SecurityOptions options = new SecurityOptions(sp);
			options.Certificate = null;
			options.Protocol=SecureProtocol.Ssl3;
			options.Entity = ConnectionEnd.Client;
			options.CommonName = ipRaw;
			options.VerificationType = CredentialVerification.None;
			options.Flags = SecurityFlags.IgnoreMaxProtocol;
			options.AllowedAlgorithms = SslAlgorithms.ALL;

			while (retry>0){
				try {
				
					s = new SecureSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp, options);
					s.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 4000);
					s.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 4000);
			
					iep	= new IPEndPoint(addr[0],Convert.ToInt32(portRaw));
					s.Connect(iep);

					ASCIIEncoding asen= new ASCIIEncoding();
					byte[] ba=asen.GetBytes(payloadRaw);
					s.Send(ba,ba.Length,System.Net.Sockets.SocketFlags.None);
					

					byte[] bb=new byte[size];
					
					int k=1;
					string response="";
					while (k>0){
						k=s.Receive(bb,size,System.Net.Sockets.SocketFlags.None);					
						response+=Encoding.Default.GetString(bb,0,k);
					}
					s.Close();
					GC.Collect();
					GC.WaitForPendingFinalizers();

					return response;

				}
				catch(Exception ex) {
					retry--;
					Thread.Sleep(1000);
				}
			}
			
			return "Timeout or retry count exceeded";
		}
예제 #2
0
파일: Wikto.cs 프로젝트: liorvh/wikto
        public string sendraw(string ipRaw, string portRaw, string payloadRaw, int size, int TimeOut, bool useSSL)
        {
            int retry = (int)updownRetryTCP.Value;
            IPHostEntry IPHost = Dns.GetHostEntry(ipRaw);
            //IPHostEntry IPHost = Dns.Resolve(ipRaw); 
            string[] aliases = IPHost.Aliases;
            IPAddress[] addr = IPHost.AddressList;
            IPEndPoint iep;
            SecureProtocol sp;
            sp = SecureProtocol.Ssl3;
            SecureSocket s = null;
            SecurityOptions options = new SecurityOptions(sp);
            options.Certificate = null;
            options.Protocol = SecureProtocol.Ssl3;
            options.Entity = ConnectionEnd.Client;
            options.CommonName = ipRaw;
            options.VerificationType = CredentialVerification.None;
            options.Flags = SecurityFlags.IgnoreMaxProtocol;
            options.AllowedAlgorithms = SslAlgorithms.ALL;

            while (retry > 0)
            {
                try
                {

                    s = new SecureSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp, options);
                    s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 4000);
                    s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 4000);

                    iep = new IPEndPoint(addr[0], Convert.ToInt32(portRaw));


                    s.Connect(iep);


                    ASCIIEncoding asen = new ASCIIEncoding();
                    byte[] ba = asen.GetBytes(payloadRaw);
                    s.Send(ba, ba.Length, System.Net.Sockets.SocketFlags.None);

                    byte[] bb = new byte[size];


                    string response = "";
                    int k = 1;
                    while (k > 0)
                    {
                        k = s.Receive(bb, size, System.Net.Sockets.SocketFlags.None);
                        for (int i = 0; i < k; i++)
                        {
                            response += Convert.ToChar(bb[i]);
                        }
                    }
                    s.Close();
                    GC.Collect();
                    GC.WaitForPendingFinalizers();

                    return response;

                }


                catch
                {
                    retry--;
                    lblStatus.Text = "Network problem - retrying\r\n";
                    lblNiktoAI.Text = "Network problem - retrying\r\n";
                    Thread.Sleep(1000);
                }
            }

            return "Retry count (" + updownRetryTCP.Value.ToString() + ") exceeded";
        }