socks
Class Proxy

java.lang.Object
  |
  +--socks.Proxy
Direct Known Subclasses:
Socks4Proxy, Socks5Proxy

public abstract class Proxy
extends java.lang.Object

Abstract class Proxy, base for classes Socks4Proxy and Socks5Proxy. Defines methods for specifying default proxy, to be used by all classes of this package.


Field Summary
static int SOCKS_ADDR_NOT_SUPPORTED
           
static int SOCKS_AUTH_FAILURE
           
static int SOCKS_AUTH_NOT_SUPPORTED
           
static int SOCKS_BADCONNECT
           
static int SOCKS_BADNETWORK
           
static int SOCKS_CMD_NOT_SUPPORTED
           
static int SOCKS_CONNECTION_REFUSED
           
static int SOCKS_DIRECT_FAILED
           
static int SOCKS_FAILURE
           
static int SOCKS_HOST_UNREACHABLE
           
static int SOCKS_JUST_ERROR
           
static int SOCKS_METHOD_NOTSUPPORTED
           
static int SOCKS_NO_PROXY
           
static int SOCKS_PROXY_IO_ERROR
           
static int SOCKS_PROXY_NO_CONNECT
           
static int SOCKS_SUCCESS
           
static int SOCKS_TTL_EXPIRE
           
 
Method Summary
 void addDirect(java.net.InetAddress ip)
          Adds given ip to the list of direct addresses.
 void addDirect(java.net.InetAddress from, java.net.InetAddress to)
          Adds given range of addresses to the lsit of direct addresses, machines within this range will be accessed without using proxy.
 boolean addDirect(java.lang.String host)
          Adds host to the list of direct addresses.
 Proxy getChainProxy()
          Get proxy which is used to connect to this proxy.
static Proxy getDefaultProxy()
          Get current default proxy.
 InetRange getDirect()
          Get the list of direct hosts.
 java.net.InetAddress getInetAddress()
          Get the ip address of the proxy server host.
 int getPort()
          Get the port on which proxy server is running.
 boolean isDirect(java.net.InetAddress host)
          Check wether the given host is on the list of direct addresses.
 boolean isDirect(java.lang.String host)
          Check wether the given host is on the list of direct address.
static Proxy parseProxy(java.lang.String proxy_entry)
          Parses strings in the form: host[:port:user:password], and creates proxy from information obtained from parsing.
 void setChainProxy(Proxy chainProxy)
          Set the proxy which should be used to connect to given proxy.
static void setDefaultProxy(java.net.InetAddress ipAddress, int port)
          Sets SOCKS5 proxy as default.
static void setDefaultProxy(java.net.InetAddress ipAddress, int port, java.lang.String user)
          Sets SOCKS4 proxy as default.
static void setDefaultProxy(Proxy p)
          Sets default proxy.
static void setDefaultProxy(java.lang.String hostName, int port)
          Sets SOCKS5 proxy as default.
static void setDefaultProxy(java.lang.String hostName, int port, java.lang.String user)
          Sets SOCKS4 proxy as default.
 void setDirect(InetRange ir)
          Sets given InetRange as the list of direct address, previous list will be discarded, any changes done previously with addDirect(Inetaddress) will be lost.
 java.lang.String toString()
          Get string representation of this proxy.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SOCKS_SUCCESS

public static final int SOCKS_SUCCESS

SOCKS_FAILURE

public static final int SOCKS_FAILURE

SOCKS_BADCONNECT

public static final int SOCKS_BADCONNECT

SOCKS_BADNETWORK

public static final int SOCKS_BADNETWORK

SOCKS_HOST_UNREACHABLE

public static final int SOCKS_HOST_UNREACHABLE

SOCKS_CONNECTION_REFUSED

public static final int SOCKS_CONNECTION_REFUSED

SOCKS_TTL_EXPIRE

public static final int SOCKS_TTL_EXPIRE

SOCKS_CMD_NOT_SUPPORTED

public static final int SOCKS_CMD_NOT_SUPPORTED

SOCKS_ADDR_NOT_SUPPORTED

public static final int SOCKS_ADDR_NOT_SUPPORTED

SOCKS_NO_PROXY

public static final int SOCKS_NO_PROXY

SOCKS_PROXY_NO_CONNECT

public static final int SOCKS_PROXY_NO_CONNECT

SOCKS_PROXY_IO_ERROR

public static final int SOCKS_PROXY_IO_ERROR

SOCKS_AUTH_NOT_SUPPORTED

public static final int SOCKS_AUTH_NOT_SUPPORTED

SOCKS_AUTH_FAILURE

public static final int SOCKS_AUTH_FAILURE

SOCKS_JUST_ERROR

public static final int SOCKS_JUST_ERROR

SOCKS_DIRECT_FAILED

public static final int SOCKS_DIRECT_FAILED

SOCKS_METHOD_NOTSUPPORTED

public static final int SOCKS_METHOD_NOTSUPPORTED
Method Detail

getPort

public int getPort()
Get the port on which proxy server is running.
Returns:
Proxy port.

getInetAddress

public java.net.InetAddress getInetAddress()
Get the ip address of the proxy server host.
Returns:
Proxy InetAddress.

addDirect

public void addDirect(java.net.InetAddress ip)
Adds given ip to the list of direct addresses. This machine will be accessed without using proxy.

addDirect

public boolean addDirect(java.lang.String host)
Adds host to the list of direct addresses. This machine will be accessed without using proxy.

addDirect

public void addDirect(java.net.InetAddress from,
                      java.net.InetAddress to)
Adds given range of addresses to the lsit of direct addresses, machines within this range will be accessed without using proxy.

setDirect

public void setDirect(InetRange ir)
Sets given InetRange as the list of direct address, previous list will be discarded, any changes done previously with addDirect(Inetaddress) will be lost. The machines in this range will be accessed without using proxy.
Parameters:
ir - InetRange which should be used to look up direct addresses.
See Also:
InetRange

getDirect

public InetRange getDirect()
Get the list of direct hosts.
Returns:
Current range of direct address as InetRange object.
See Also:
InetRange

isDirect

public boolean isDirect(java.lang.String host)
Check wether the given host is on the list of direct address.
Parameters:
host - Host name to check.
Returns:
true if the given host is specified as the direct addresses.

isDirect

public boolean isDirect(java.net.InetAddress host)
Check wether the given host is on the list of direct addresses.
Parameters:
host - Host address to check.
Returns:
true if the given host is specified as the direct address.

setChainProxy

public void setChainProxy(Proxy chainProxy)
Set the proxy which should be used to connect to given proxy.
Parameters:
chainProxy - Proxy to use to connect to this proxy.

getChainProxy

public Proxy getChainProxy()
Get proxy which is used to connect to this proxy.
Returns:
Proxy which is used to connect to this proxy, or null if proxy is to be contacted directly.

toString

public java.lang.String toString()
Get string representation of this proxy.
Overrides:
toString in class java.lang.Object

setDefaultProxy

public static void setDefaultProxy(java.lang.String hostName,
                                   int port,
                                   java.lang.String user)
                            throws java.net.UnknownHostException
Sets SOCKS4 proxy as default.
Parameters:
hostName - Host name on which SOCKS4 server is running.
port - Port on which SOCKS4 server is running.
user - Username to use for communications with proxy.

setDefaultProxy

public static void setDefaultProxy(java.net.InetAddress ipAddress,
                                   int port,
                                   java.lang.String user)
Sets SOCKS4 proxy as default.
Parameters:
ipAddress - Host address on which SOCKS4 server is running.
port - Port on which SOCKS4 server is running.
user - Username to use for communications with proxy.

setDefaultProxy

public static void setDefaultProxy(java.lang.String hostName,
                                   int port)
                            throws java.net.UnknownHostException
Sets SOCKS5 proxy as default. Default proxy only supports no-authentication.
Parameters:
hostName - Host name on which SOCKS5 server is running.
port - Port on which SOCKS5 server is running.

setDefaultProxy

public static void setDefaultProxy(java.net.InetAddress ipAddress,
                                   int port)
Sets SOCKS5 proxy as default. Default proxy only supports no-authentication.
Parameters:
ipAddress - Host address on which SOCKS5 server is running.
port - Port on which SOCKS5 server is running.

setDefaultProxy

public static void setDefaultProxy(Proxy p)
Sets default proxy.
Parameters:
p - Proxy to use as default proxy.

getDefaultProxy

public static Proxy getDefaultProxy()
Get current default proxy.
Returns:
Current default proxy, or null if none is set.

parseProxy

public static Proxy parseProxy(java.lang.String proxy_entry)
Parses strings in the form: host[:port:user:password], and creates proxy from information obtained from parsing.

Defaults: port = 1080.
If user specified but not password, creates Socks4Proxy, if user not specified creates Socks5Proxy, if both user and password are speciefied creates Socks5Proxy with user/password authentication.

Parameters:
proxy_entry - String in the form host[:port:user:password]
Returns:
Proxy created from the string, null if entry was somehow invalid(host unknown for example, or empty string)