亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? cproxy.java

?? java環境下完整的sock4/sock5包裝類
?? JAVA
字號:
/*************************************************************************
 FILE :		  CProxy.java

 Author :	  Svetoslav Tchekanov  (swetoslav@iname.com)

 Description: CProxy class definition.

			  CProxy.class is the implementation of TCP Proxy server


 Copyright notice:
	Written by Svetoslav Tchekanov (swetoslav@iname.com)
	Copyright(c) 2000

This code may be used in compiled form in any way you desire. This
file may be redistributed unmodified by any means PROVIDING it is 
not sold for profit without the authors written consent, and 
providing that this notice and the authors name is included. If 
the source code in this file is used in any commercial application 
then a simple email would be nice.

This file is provided "as is" with no expressed or implied warranty.
The author accepts no liability if it causes any damage to your
computer.

*************************************************************************/


package	socksshttp;

///////////////////////////////////////////////

import	java.io.*;
import	java.net.*;

///////////////////////////////////////////////

public class CProxy	implements	Runnable
{
	protected	Object	m_lock;
	
	public static final int	DEFAULT_BUF_SIZE = 4096;
	
	protected	Thread		m_TheThread	= null;
	
	protected	CServer			m_SocksServer	= null;
	public	CServer	getSocksServer()	{	return m_SocksServer;	}
	
	public	Socket			m_ClientSocket	= null;
	public	Socket			m_ServerSocket	= null;
	
	public	int				m_BufLen		= DEFAULT_BUF_SIZE;
	public	byte[]			m_Buffer		= null;
	
	public	InputStream		m_ClientInput	= null;
	public	OutputStream	m_ClientOutput	= null;
	public	InputStream		m_ServerInput	= null;
	public	OutputStream	m_ServerOutput	= null;
	
	public static final int DEFAULT_TIMEOUT	= 10;
	
	protected	boolean	m_bUseSHttpProxy	= false;
	protected	String	m_cProxyHost		= null;
	protected	int		m_nProxyPort		= 0;
	
	public	boolean	doUseSHttpProxy(){	return	m_bUseSHttpProxy;	}
	public	int		getProxyPort()	{	return	m_nProxyPort;	}
	public	String	getProxyHost()	{	return	m_cProxyHost; 	}

	///////////////////////////////////////////////
	
	public	CProxy( CServer SocksServer, Socket ClientSocket )
	{
		m_lock = this;
		
		m_SocksServer = SocksServer;
		if( m_SocksServer == null )	{
			Close();
			return;
		}
		
		m_ClientSocket = ClientSocket;
		if( m_ClientSocket != null )	{
			try	{
				m_ClientSocket.setSoTimeout( DEFAULT_TIMEOUT );
			}
			catch( SocketException e )	{
				Log.Error( "Socket Exception during seting Timeout." );
			}
		}
		m_bUseSHttpProxy= m_SocksServer.m_bUseSHttpProxy;
		m_cProxyHost	= m_SocksServer.m_cProxyHost;
		m_nProxyPort	= m_SocksServer.m_nProxyPort;
		
		m_Buffer = new byte[ m_BufLen ];
		
		Log.Println( "Proxy Created." );
	}
	
	///////////////////////////////////////////////
	
	public	void	SetLock( Object lock )
	{
		this.m_lock = lock;
	}
	
	
	///////////////////////////////////////////////

	public	void	start()
	{
		m_TheThread = new Thread( this );
		m_TheThread.start();
		Log.Println( "Proxy Started." );
	}
	/////////////////////////////////////////////////////////////

	public	void	stop()	{
	
		try	{
			if( m_ClientSocket != null )	m_ClientSocket.close();
			if( m_ServerSocket  != null )	m_ServerSocket.close();
		}
		catch( IOException e )	{
		}
		
		m_ClientSocket = null;
		m_ServerSocket  = null;
		
		Log.Println( "Proxy Stopped." );
		
		m_TheThread.stop();
	}
	
	/////////////////////////////////////////////////////////////
//	Common part of the server

	public	void	run()
	{
		SetLock( this );
		
		if( ! PrepareClient() )	{
			Log.Error( "Proxy - client socket is null !" );
			return;
		}

		ProcessRelay();

		Close();
	}
	///////////////////////////////////////////////
	///////////////////////////////////////////////

	public	void	Close()		{
		try	{
			if( m_ClientOutput != null )	{
				m_ClientOutput.flush();
				m_ClientOutput.close();
			}
		}
		catch( IOException e )	{
		}
		try	{
			if( m_ServerOutput != null )	{
				m_ServerOutput.flush();
				m_ServerOutput.close();
			}
		}
		catch( IOException e )	{
		}
		
		try	{
			if( m_ClientSocket != null )	{
					m_ClientSocket.close();
				}
			}
			catch( IOException e )	{
		}
		
		try	{
			if( m_ServerSocket != null )	{
					m_ServerSocket.close();
				}
			}
			catch( IOException e )	{
		}
		
		m_ServerSocket = null;
		m_ClientSocket = null;
		
		Log.Println( "Proxy Closed." );
	}
	///////////////////////////////////////////////
	///////////////////////////////////////////////
	
	public	void	SendToClient( byte[] Buf )	{
		
		SendToClient( Buf, Buf.length );
	}
	//--------------
	public	void	SendToClient( byte[] Buf, int Len )	{
		if( m_ClientOutput == null )		return;
		if( Len <= 0 || Len > Buf.length )	return;
		
		try	{
			m_ClientOutput.write( Buf, 0, Len );
			m_ClientOutput.flush();
		}
		catch( IOException e )	{
			Log.Error( "Sending data to client" );
		}
	}
	///////////////////////////////////////////////
	
	public	void	SendToServer( byte[] Buf )	{
		
		SendToServer( Buf, Buf.length );
	}
	//----------------
	public	void	SendToServer( byte[] Buf, int Len )	{
		if( m_ServerOutput == null )		return;
		if( Len <= 0 || Len > Buf.length )	return;
		
		try	{
			m_ServerOutput.write( Buf, 0, Len );
			m_ServerOutput.flush();
		}
		catch( IOException e )	{
			Log.Error( "Sending data to server" );
		}
	}
	
	///////////////////////////////////////////////
	
	public	boolean	isActive()	{
		return	(m_ClientSocket != null && m_ServerSocket != null);	
	}
	
	///////////////////////////////////////////////
	///////////////////////////////////////////////
	
	public	void	ConnectToServer( String Server, int port ) 
		throws IOException, UnknownHostException
	{
	//	Connect to the Remote Host
		
		if( Server.equals("") )	{
			Close();
			Log.Error( "Invalid Remote Host Name - Empty String !!!" );
			return;
		}
		
		if( m_bUseSHttpProxy )	{
			Server = m_cProxyHost;
			port   = m_nProxyPort;
		}
		
		m_ServerSocket = new Socket( Server, port );
		m_ServerSocket.setSoTimeout( DEFAULT_TIMEOUT );
		
		Log.Println( "Connected to "+Log.getSocketInfo( m_ServerSocket ) );
		PrepareServer();
	}
	/////////////////////////////////////////////////////////////
	protected	void	PrepareServer()	throws IOException	{
	synchronized( m_lock )
	{
		m_ServerInput  = m_ServerSocket.getInputStream();
		m_ServerOutput = m_ServerSocket.getOutputStream();
	}
	}
	/////////////////////////////////////////////////////////////
	
	public	boolean	PrepareClient()	{
		if( m_ClientSocket == null )	return false;

		try	{
			m_ClientInput = m_ClientSocket.getInputStream();
			m_ClientOutput= m_ClientSocket.getOutputStream();
		}
		catch( IOException e )	{
			Log.Error( "Proxy - can't get I/O streams!" );
			Log.Error( e );
			return	false;
		}
		return	true;
	}

	///////////////////////////////////////////////
	
	static	final	byte	SOCKS5_Version	= 0x05;
	static	final	byte	SOCKS4_Version	= 0x04;

	CSocks4	comm = null;
	
	public	void	ProcessRelay()	{
		
		try	{
			byte	SOCKS_Version	= GetByteFromClient();
			
			switch( SOCKS_Version )	{
			case SOCKS4_Version:	comm = new CSocks4( this );
									break;
			case SOCKS5_Version:	comm = new CSocks5( this );	
									break;
			default:	Log.Error( "Invalid SOKCS version : "+SOCKS_Version );
						return;
			}
			Log.Println( "Accepted SOCKS "+SOCKS_Version+" Request." );
						
			comm.Authenticate( SOCKS_Version );
			comm.GetClientCommand();
			
			switch ( comm.Command )	{
			case CSocks4.SC_CONNECT	:	comm.Connect();
										if( doUseSHttpProxy() )	{
											CreateSSLTunnel();
										}
										Relay();
										break;
			
			case CSocks4.SC_BIND	:	comm.Bind();
										Relay();
										break;
			
			case CSocks4.SC_UDP		:	comm.UDP();
										break;
			}
		}
		catch( Exception   e )	{
			Log.Error( e );
		}
	} // ProcessRelay
	
	/////////////////////////////////////////////////////////////

	public	byte	GetByteFromClient()
		throws Exception
	{
		int	b;
		
		while( m_ClientSocket != null )		{
			
			try	{
				b = m_ClientInput.read();
			}
			catch( InterruptedIOException e )		{
				Thread.yield();
				continue;
			}
						
			return (byte)b; // return loaded byte
	
		} // while...
		throw	new Exception( "Interrupted Reading GetByteFromClient()");
	} // GetByteFromClient()...
	///////////////////////////////////////////////
	
	///////////////////////////////////////////////
	
	public	static	final	String	EOL = "\r\n";
	
	///////////////////////////////////////////////
	
	public	void	CreateSSLTunnel()
		throws	Exception
	{
		Log.Println( "Initiating SSL Tunneling..." );
		
		String	Host = comm.m_ServerIP.getHostAddress();
		String	cmd = "CONNECT "+Host+":"+comm.m_nServerPort+
					  " HTTP/1.0"+EOL+EOL;

		SendToServer( cmd.getBytes() );
		
		// Wait for Proxy Reply...
		int	dlen = 0;
		while( dlen == 0 )	{
			try	{
				dlen = m_ServerInput.read( m_Buffer, 0, m_BufLen );
				if( dlen > 0 )	{
					String	s = new String( m_Buffer, 0, dlen );
					if( s.startsWith( "HTTP/1.0 200" ) ||
						s.startsWith( "HTTP/1.1 200" ) )
					{
						Log.Println( "SHTTP Proxy Reply : [Connection Established]" );
					}
					else	{
						Log.Println( "SHTTP Proxy Reply : ["+s.trim()+"]" );
						throw new Exception("Error Response from SHTTP Proxy !");
					}
				}
			}
			catch( InterruptedIOException e )	{
				dlen = 0;
			}
		}// While...
	}
	///////////////////////////////////////////////
	
	public	void	Relay()	{
	
		boolean	Active		= true;
		int		dlen		= 0;

		while( Active )	{
			
		//---> Check for client data <---
			
			dlen = CheckClientData();
			
			if( dlen < 0 )	Active = false;
			if( dlen > 0 )	{
				LogClientData( dlen );
				SendToServer( m_Buffer, dlen );
			}
			
			//---> Check for Server data <---
			dlen = CheckServerData();
			
			if( dlen < 0 )	Active = false;
			if( dlen > 0 )	{
				LogServerData( dlen );
				SendToClient( m_Buffer, dlen );
			}
			
			Thread.currentThread().yield();
		}	// while
	}
	
	/////////////////////////////////////////////////////////////

	public	int		CheckClientData()	{
	synchronized( m_lock )
	{
	//	The client side is not opened.
		if( m_ClientInput == null )	return -1;

		int	dlen = 0;

		try
		{
			dlen = m_ClientInput.read( m_Buffer, 0, m_BufLen );
		}
		catch( InterruptedIOException e )		{
			return	0;
		}
		catch( IOException e )		{
			Log.Println( "Client connection Closed!" );
			Close();	//	Close the server on this exception
			return -1;
		}

		if( dlen < 0 )	Close();

		return	dlen;
	}
	}
	///////////////////////////////////////////////
	/////////////////////////////////////////////////////////////

	public	int		CheckServerData()	{
	synchronized( m_lock )
	{
	//	The client side is not opened.
		if( m_ServerInput == null )	return -1;

		int	dlen = 0;

		try
		{
			dlen = m_ServerInput.read( m_Buffer, 0, m_BufLen );
		}
		catch( InterruptedIOException e )		{
			return	0;
		}
		catch( IOException e )		{
			Log.Println( "Server connection Closed!" );
			Close();	//	Close the server on this exception
			return -1;
		}

		if( dlen < 0 )	Close();

		return	dlen;
	}
	}
	///////////////////////////////////////////////

	///////////////////////////////////////////////
	
	public	void	LogServerData( int traffic )	{
		Log.Println("Srv data : "+
					Log.getSocketInfo( m_ClientSocket ) +
					" << <"+
					comm.m_ServerIP.getHostName()+"/"+
					comm.m_ServerIP.getHostAddress()+":"+
					comm.m_nServerPort+"> : " + 
					traffic +" bytes." );
	}
	
	///////////////////////////////////////////////
	
	public	void	LogClientData( int traffic )	{
		Log.Println("Cli data : "+
					Log.getSocketInfo( m_ClientSocket ) +
					" >> <"+
					comm.m_ServerIP.getHostName()+"/"+
					comm.m_ServerIP.getHostAddress()+":"+
					comm.m_nServerPort+"> : " + 
					traffic +" bytes." );
	}
	
	///////////////////////////////////////////////
}
///////////////////////////////////////////////////

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
中文字幕乱码一区二区免费| 欧美精品99久久久**| 久久精品人人做人人爽人人| 国产精品18久久久| 亚洲国产精品传媒在线观看| 成人亚洲一区二区一| 一区精品在线播放| 日本久久一区二区三区| 午夜成人在线视频| 精品日韩在线一区| 岛国av在线一区| 亚洲色图欧美激情| 欧美久久高跟鞋激| 国产一区二区三区在线观看免费 | 久久爱www久久做| 2024国产精品视频| 99re亚洲国产精品| 日韩电影一二三区| 久久久久久久网| 91免费国产在线观看| 香港成人在线视频| 国产亚洲精久久久久久| 色婷婷久久综合| 九九九精品视频| 成人免费在线播放视频| 欧美精品三级在线观看| 国产尤物一区二区在线| 亚洲精品国产品国语在线app| 91麻豆精品国产综合久久久久久 | 国产毛片精品国产一区二区三区| 国产精品激情偷乱一区二区∴| 日本精品免费观看高清观看| 毛片av中文字幕一区二区| 国产精品福利一区二区| 这里只有精品电影| 色综合欧美在线| 九九久久精品视频| 亚洲妇熟xx妇色黄| 国产精品网友自拍| 欧美一级国产精品| 91福利国产精品| 国产传媒欧美日韩成人| 丝袜美腿亚洲色图| 综合精品久久久| 久久久国际精品| 91精品视频网| 色婷婷狠狠综合| 成人免费观看视频| 老司机精品视频在线| 无吗不卡中文字幕| 亚洲免费色视频| 国产网站一区二区三区| 欧美一区二区三区色| 日本久久电影网| 99riav久久精品riav| 国产成人午夜电影网| 免费国产亚洲视频| 亚洲图片欧美视频| 成人欧美一区二区三区白人| 久久综合九色欧美综合狠狠| 制服丝袜亚洲精品中文字幕| 在线观看日韩电影| 91无套直看片红桃| 99久久er热在这里只有精品66| 国产黄色91视频| 国模一区二区三区白浆| 久久99精品国产.久久久久久| 午夜婷婷国产麻豆精品| 一区二区三区在线观看国产| 亚洲欧洲在线观看av| 中文欧美字幕免费| 国产精品久久久久久久久久久免费看 | 日韩欧美一区在线| 欧美一区二区免费视频| 欧美久久久久免费| 日韩一区二区三区视频在线| 555夜色666亚洲国产免| 这里只有精品视频在线观看| 91精品国产综合久久香蕉的特点 | 日韩免费看的电影| 91精品在线麻豆| 日韩免费高清av| 日韩欧美国产系列| 久久这里只有精品6| 久久久美女毛片| 国产精品久久久久久一区二区三区 | 国产精品一区一区三区| 国产精品99久久久久| 国产精品一级片| 粉嫩欧美一区二区三区高清影视 | 亚洲精品视频观看| 亚洲一区在线观看视频| 日韩精品视频网| 久久91精品国产91久久小草| 国产一区二区网址| www.日韩av| 欧美区一区二区三区| 欧美大片日本大片免费观看| 久久九九影视网| 成人免费在线播放视频| 亚洲高清视频的网址| 黄色成人免费在线| 成人小视频免费在线观看| 99久久精品国产网站| 7799精品视频| 久久久久99精品一区| 亚洲精品国产一区二区精华液 | 舔着乳尖日韩一区| 国内精品写真在线观看| 99vv1com这只有精品| 678五月天丁香亚洲综合网| 久久久午夜精品理论片中文字幕| 亚洲欧洲精品一区二区三区不卡| 亚洲最色的网站| 麻豆91在线观看| voyeur盗摄精品| 欧美一级一级性生活免费录像| 日本一区二区视频在线观看| 亚洲午夜久久久久中文字幕久| 麻豆久久一区二区| 91视频xxxx| 精品人伦一区二区色婷婷| 亚洲色图20p| 国产一区二区视频在线播放| 欧美午夜精品久久久久久孕妇| 欧美成人女星排行榜| 亚洲精选视频在线| 国产精品456露脸| 欧美日免费三级在线| 欧美国产乱子伦| 视频一区二区三区中文字幕| 国产乱人伦精品一区二区在线观看 | 免费高清不卡av| 色综合天天做天天爱| 日韩欧美中文字幕制服| 亚洲一区日韩精品中文字幕| 国产乱码精品一区二区三区忘忧草| 色先锋资源久久综合| 国产无人区一区二区三区| 秋霞午夜鲁丝一区二区老狼| 91色乱码一区二区三区| www国产精品av| 麻豆一区二区三| 91成人在线免费观看| 国产精品久久久99| 久久国产日韩欧美精品| 欧美日韩和欧美的一区二区| 国产精品卡一卡二卡三| 国产尤物一区二区在线| 日韩欧美国产一区二区在线播放| 玉足女爽爽91| a在线播放不卡| 久久精品亚洲精品国产欧美kt∨| 蜜桃精品在线观看| 欧美日韩免费观看一区二区三区| 亚洲欧美综合色| 99视频国产精品| 中文字幕成人av| 成人免费av在线| 中文字幕乱码久久午夜不卡| 国产一区二区三区综合| 精品久久久影院| 久久99国产精品尤物| 在线播放亚洲一区| 亚洲成人777| 欧美日韩一区视频| 亚洲观看高清完整版在线观看| 在线免费观看日本欧美| 一区二区欧美视频| 在线看国产一区| 亚洲一二三专区| 欧美日韩成人综合天天影院| 亚洲二区视频在线| 这里是久久伊人| 麻豆精品在线视频| 26uuu国产日韩综合| 国产真实乱子伦精品视频| 精品对白一区国产伦| 精品影院一区二区久久久| 精品日韩欧美在线| 国产一区二区导航在线播放| 久久久午夜精品理论片中文字幕| 国产一区二区毛片| 国产精品欧美极品| 91免费在线看| 亚洲电影一区二区三区| 欧美一卡2卡三卡4卡5免费| 久久99精品国产麻豆婷婷 | 91在线观看高清| 亚洲在线免费播放| 91精品国产综合久久福利软件| 日产国产欧美视频一区精品| 日韩欧美久久一区| 丁香另类激情小说| 亚洲黄色免费网站| 日韩精品一区二区三区蜜臀| 国产精品一二三在| 亚洲乱码中文字幕综合| 7777精品伊人久久久大香线蕉的 | 久久精品综合网|