📄 redirectengine.java
字号:
package javatunnel;import java.io.*;import java.net.*;/** * * 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 RedirectEngine extends Engine { private Configuration configuration; public RedirectEngine(Configuration config) { configuration = config; if(configuration.isManageHostsFile()){ addToHostFile(configuration.getDestinationAddress()); } System.out.println("-->Creating redirection:"); System.out.println( " |-->Listener local port: " + configuration.getLocalPort()); System.out.println( " |-->Redirecting to: " + configuration.getDestinationAddress() + ":" + configuration.getDestinationPort()); System.out.println(""); } 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 Redirect Engine"); return; } ioe.printStackTrace(); System.out.println("Error en el bucle de aceptacion de conexiones"); System.exit(1); } } DataHandler getIncomingDataHandler(Socket local, Socket remote) { return new DefaultDataHandler(local, remote); } DataHandler getOutcomingDataHandler(Socket local, Socket remote) { return new DefaultDataHandler(remote, local); } private Socket openConnection() { try { System.out.println( "Serving connection request to: " + configuration.getDestinationAddress() + " : " + configuration.getDestinationPort()); return new Socket( configuration.getDestinationAddress(), configuration.getDestinationPort()); } catch (IOException ioe) { System.out.println( "Error connecting to: " + configuration.getDestinationAddress() + " : " + configuration.getDestinationPort() + "\nDetails: " + ioe); ioe.printStackTrace(); } return null; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -