anecho.extranet
Class Socks5socket

java.lang.Object
  extended by java.net.Socket
      extended by anecho.extranet.Socks5socket

public class Socks5socket
extends java.net.Socket

Extension of the standard Socket class to enable connections through a socks5 server.

Does NO authentification yet!

This class is a straightforward implementation of the SOCKS5 client protocol as described in RFC.... Unfortunately it is just capable of identifying itself with username and password since I was not able to find a Java GSSAPI and furthermore was the administrator of the SOCKS server myself so I could configure it to accept username password authentification.

Usage:

        private void tconnect(String host, int port, boolean socks){
                Socket s=null;
                String buff=null;
                try{
                        if (socks) s=(Socket)new Socks5socket(host, port);
                        else s=new Socket(host, port);
                        ...
                }catch (IOException e){
                        output.append("Connection refused.\n"+e+"\n");
                }finally{
                        output.append("Connection closed.\n");
                        if (s != null) try{s.close();}catch(IOException ce){;}
                }
        }
 


Constructor Summary
Socks5socket(java.lang.String hostname, int port)
          the standardconstructor.
Socks5socket(java.lang.String hostname, int port, java.lang.String s5Host, int s5Port)
           
 
Method Summary
 java.lang.String getHost()
          Returns the IP address of the Socks server.
 int getPort()
          Returns the portnumber of the Socks server.
 
Methods inherited from class java.net.Socket
bind, close, connect, connect, getChannel, getInetAddress, getInputStream, getKeepAlive, getLocalAddress, getLocalPort, getLocalSocketAddress, getOOBInline, getOutputStream, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getSoLinger, getSoTimeout, getTcpNoDelay, getTrafficClass, isBound, isClosed, isConnected, isInputShutdown, isOutputShutdown, sendUrgentData, setKeepAlive, setOOBInline, setPerformancePreferences, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSocketImplFactory, setSoLinger, setSoTimeout, setTcpNoDelay, setTrafficClass, shutdownInput, shutdownOutput, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Socks5socket

public Socks5socket(java.lang.String hostname,
                    int port)
             throws java.net.UnknownHostException,
                    java.io.IOException
the standardconstructor.

This constructor feels exactly like a standard Socket, it just opens a connection to the SOCKS server first, negotiates the credentials and requests a connect to the remote host on success.

Parameters:
hostname - the name of the remote host to connect to.
port - the portnumber on the remote host to connect to.
Throws:
java.net.UnknownHostException - if the host could not be resolved.
java.io.IOException - if any error occured on connection.

Socks5socket

public Socks5socket(java.lang.String hostname,
                    int port,
                    java.lang.String s5Host,
                    int s5Port)
             throws java.net.UnknownHostException,
                    java.io.IOException
Parameters:
hostname -
port -
s5Host -
s5Port -
Throws:
java.net.UnknownHostException
java.io.IOException
Method Detail

getHost

public java.lang.String getHost()
Returns the IP address of the Socks server.

This just prints out the IP-Address that was returned after the request. Eventually we need this in a cascaded proxy environment since the SOCKS definition is capable of load balancing connections between different servers.

Returns:
the IP-address in a String.

getPort

public int getPort()
Returns the portnumber of the Socks server.

This just prints out the portnumber that was returned after the request. Eventually we need this in a cascaded proxy environment since the SOCKS definition is capable of load balancing connections between different servers.

Overrides:
getPort in class java.net.Socket
Returns:
the portnumber.