⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sslproxyengine.java

📁 java实现的代理程序 socket 编程实现的http 和socket 代理程序
💻 JAVA
字号:
package javatunnel;import java.net.*;import java.io.*;/** *  * JavaTunnel *  * Copyright (C) 2002 Andr閟 Ederra *  * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. *  * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. *  * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place - Suite 330, Boston, MA 02111-1307, USA. */public class SSLProxyEngine extends Engine {	private Configuration configuration;	public SSLProxyEngine(Configuration config) {		configuration = config;		if(configuration.isManageHostsFile()){			addToHostFile(configuration.getDestinationAddress());			}		System.out.println("-->Creating SSL Proxy Bouncer:");		System.out.println(			"  |-->Listener local port: " + configuration.getLocalPort());		System.out.println(			"  |-->Redirecting to: "				+ configuration.getDestinationAddress()				+ ":"				+ configuration.getDestinationPort());		System.out.println(			"  |-->Bouncing into proxy: "				+ configuration.getProxyAddress()				+ ":"				+ configuration.getProxyPort());		System.out.println("");	}	DataHandler getOutcomingDataHandler(Socket local, Socket remote) {		return new DefaultDataHandler(local, remote);	}	DataHandler getIncomingDataHandler(Socket local, Socket remote) {		return new DefaultDataHandler(remote, local);	}	private Socket openConnection() {		Socket proxySocket;		StringBuffer connectString = new StringBuffer("CONNECT ");		connectString.append(			configuration.getDestinationAddress()				+ ":"				+ configuration.getDestinationPort()				+ " HTTP/1.0\r\n\r\n");		byte[] connectByteArray = connectString.toString().getBytes();		try {			proxySocket =				new Socket(					configuration.getProxyAddress(),					configuration.getProxyPort());			proxySocket.getOutputStream().write(				connectByteArray,				0,				connectByteArray.length);			proxySocket.getOutputStream().flush();			BufferedReader lineReader =				new BufferedReader(					new InputStreamReader(proxySocket.getInputStream()));			StringBuffer response = new StringBuffer();			//Read the response until a double blanck line is found			boolean proxyAnswered = false;			while (!proxyAnswered) {				int i = lineReader.read();				if (i == -1) {					//EOF ??				}				char c = (char) i;				response.append(c);				if (c == '\r') {					char[] buffer = new char[3];					i = lineReader.read(buffer, 0, 3);					if (i == -1) {						//EOF ??					}					if (i == 3						&& buffer[0] == '\n'						&& buffer[1] == '\r'						&& buffer[2] == '\n') {						proxyAnswered = true;					}				}			}			System.out.println("Respuesta del proxy: " + response);		} catch (IOException ioe) {			ioe.printStackTrace();			System.out.println(				"Error estableciendo CONNECT con el proxy\nExcepci髇: " + ioe);			return null;		}		return proxySocket;	}	public void listen() {		try {			System.out.println(				"Awaiting connections at port: "					+ configuration.getLocalPort());			serverSocket = new ServerSocket(configuration.getLocalPort());		} catch (IOException ioe) {			ioe.printStackTrace();			System.out.println(				"Error creating server socket in port: "					+ configuration.getLocalPort());			System.exit(1);		}		try {			Socket incoming;			Socket outcoming;			while (true) {						incoming = serverSocket.accept();							System.out.println(					"Received connection  request from: "						+ incoming.getRemoteSocketAddress());				outcoming = openConnection();				DataHandler inDatahandler =					getIncomingDataHandler(incoming, outcoming);				incomingHandlers.add(inDatahandler);				inDatahandler.start();				DataHandler outDatahandler =					getOutcomingDataHandler(incoming, outcoming);				outcomingHandlers.add(outDatahandler);				outDatahandler.start();			}		} catch (IOException ioe) {			if (terminate) {				System.out.println("Terminating SSL Proxy Engine");				return;			}			ioe.printStackTrace();			System.out.println("Error en el bucle de aceptacion de conexiones");			System.exit(1);		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -