public abstract class Proxy extends Object
Modifier and Type | Field and Description |
---|---|
protected Proxy |
chainProxy |
protected static Proxy |
defaultProxy |
protected InetRange |
directHosts |
protected InputStream |
in |
protected OutputStream |
out |
protected String |
proxyHost |
protected InetAddress |
proxyIP |
protected int |
proxyPort |
protected Socket |
proxySocket |
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 |
protected int |
version |
Modifier and Type | Method and Description |
---|---|
protected ProxyMessage |
accept() |
void |
addDirect(InetAddress ip)
Adds given ip to the list of direct addresses.
|
void |
addDirect(InetAddress from,
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(String host)
Adds host to the list of direct addresses.
|
protected ProxyMessage |
bind(InetAddress ip,
int port) |
protected ProxyMessage |
bind(String host,
int port) |
protected ProxyMessage |
connect(InetAddress ip,
int port) |
protected ProxyMessage |
connect(String host,
int port) |
protected abstract Proxy |
copy() |
protected void |
endSession() |
protected ProxyMessage |
exchange(ProxyMessage request)
Sends the request reads reply and returns it
throws exception if something wrong with IO
or the reply code is not zero
|
protected abstract ProxyMessage |
formMessage(InputStream in) |
protected abstract ProxyMessage |
formMessage(int cmd,
InetAddress ip,
int port) |
protected abstract ProxyMessage |
formMessage(int cmd,
String host,
int port) |
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.
|
InetAddress |
getInetAddress()
Get the ip address of the proxy server host.
|
int |
getPort()
Get the port on which proxy server is running.
|
boolean |
isDirect(InetAddress host)
Check wether the given host is on the list of direct addresses.
|
boolean |
isDirect(String host)
Check wether the given host is on the list of direct address.
|
static Proxy |
parseProxy(String proxy_entry)
Parses strings in the form: host[:port:user:password], and creates
proxy from information obtained from parsing.
|
protected ProxyMessage |
readMsg()
Reads the reply from the SOCKS server
|
protected void |
sendMsg(ProxyMessage msg)
Sends the request to SOCKS server
|
void |
setChainProxy(Proxy chainProxy)
Set the proxy which should be used to connect to given proxy.
|
static void |
setDefaultProxy(InetAddress ipAddress,
int port)
Sets SOCKS5 proxy as default.
|
static void |
setDefaultProxy(InetAddress ipAddress,
int port,
String user)
Sets SOCKS4 proxy as default.
|
static void |
setDefaultProxy(Proxy p)
Sets default proxy.
|
static void |
setDefaultProxy(String hostName,
int port)
Sets SOCKS5 proxy as default.
|
static void |
setDefaultProxy(String hostName,
int port,
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.
|
protected void |
startSession() |
String |
toString()
Get string representation of this proxy.
|
protected ProxyMessage |
udpAssociate(InetAddress ip,
int port) |
protected ProxyMessage |
udpAssociate(String host,
int port) |
protected InetRange directHosts
protected InetAddress proxyIP
protected String proxyHost
protected int proxyPort
protected Socket proxySocket
protected InputStream in
protected OutputStream out
protected int version
protected Proxy chainProxy
protected static Proxy defaultProxy
public static final int SOCKS_SUCCESS
public static final int SOCKS_FAILURE
public static final int SOCKS_BADCONNECT
public static final int SOCKS_BADNETWORK
public static final int SOCKS_HOST_UNREACHABLE
public static final int SOCKS_CONNECTION_REFUSED
public static final int SOCKS_TTL_EXPIRE
public static final int SOCKS_CMD_NOT_SUPPORTED
public static final int SOCKS_ADDR_NOT_SUPPORTED
public static final int SOCKS_NO_PROXY
public static final int SOCKS_PROXY_NO_CONNECT
public static final int SOCKS_PROXY_IO_ERROR
public static final int SOCKS_AUTH_NOT_SUPPORTED
public static final int SOCKS_AUTH_FAILURE
public static final int SOCKS_JUST_ERROR
public static final int SOCKS_DIRECT_FAILED
public static final int SOCKS_METHOD_NOTSUPPORTED
public int getPort()
public InetAddress getInetAddress()
public void addDirect(InetAddress ip)
public boolean addDirect(String host)
public void addDirect(InetAddress from, InetAddress to)
public void setDirect(InetRange ir)
ir
- InetRange which should be used to look up direct addresses.InetRange
public InetRange getDirect()
InetRange
public boolean isDirect(String host)
host
- Host name to check.public boolean isDirect(InetAddress host)
host
- Host address to check.public void setChainProxy(Proxy chainProxy)
chainProxy
- Proxy to use to connect to this proxy.public Proxy getChainProxy()
public String toString()
public static void setDefaultProxy(String hostName, int port, String user) throws UnknownHostException
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.UnknownHostException
public static void setDefaultProxy(InetAddress ipAddress, int port, String user)
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.public static void setDefaultProxy(String hostName, int port) throws UnknownHostException
hostName
- Host name on which SOCKS5 server is running.port
- Port on which SOCKS5 server is running.UnknownHostException
public static void setDefaultProxy(InetAddress ipAddress, int port)
ipAddress
- Host address on which SOCKS5 server is running.port
- Port on which SOCKS5 server is running.public static void setDefaultProxy(Proxy p)
p
- Proxy to use as default proxy.public static Proxy getDefaultProxy()
public static Proxy parseProxy(String proxy_entry)
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.
proxy_entry
- String in the form host[:port:user:password]protected void startSession() throws SocksException
SocksException
protected abstract Proxy copy()
protected abstract ProxyMessage formMessage(int cmd, InetAddress ip, int port)
protected abstract ProxyMessage formMessage(int cmd, String host, int port) throws UnknownHostException
UnknownHostException
protected abstract ProxyMessage formMessage(InputStream in) throws SocksException, IOException
SocksException
IOException
protected ProxyMessage connect(InetAddress ip, int port) throws SocksException
SocksException
protected ProxyMessage connect(String host, int port) throws UnknownHostException, SocksException
UnknownHostException
SocksException
protected ProxyMessage bind(InetAddress ip, int port) throws SocksException
SocksException
protected ProxyMessage bind(String host, int port) throws UnknownHostException, SocksException
UnknownHostException
SocksException
protected ProxyMessage accept() throws IOException, SocksException
IOException
SocksException
protected ProxyMessage udpAssociate(InetAddress ip, int port) throws SocksException
SocksException
protected ProxyMessage udpAssociate(String host, int port) throws UnknownHostException, SocksException
UnknownHostException
SocksException
protected void endSession()
protected void sendMsg(ProxyMessage msg) throws SocksException, IOException
SocksException
IOException
protected ProxyMessage readMsg() throws SocksException, IOException
SocksException
IOException
protected ProxyMessage exchange(ProxyMessage request) throws SocksException
SocksException
Copyright © 2024. All rights reserved.