public class Socks5 extends Object implements SocksProxy
Socks5
has implements SOCKS5 protocol.Modifier and Type | Field and Description |
---|---|
static byte |
AUTHENTICATION_SUCCEEDED
Authentication succeeded code.
|
protected static org.slf4j.Logger |
logger
Logger.
|
static int |
REP_ADDRESS_TYPE_NOT_SUPPORTED |
static int |
REP_COMMAND_NOT_SUPPORTED |
static int |
REP_CONNECTION_NOT_ALLOWED_BY_RULESET |
static int |
REP_CONNECTION_REFUSED |
static int |
REP_GENERAL_SOCKS_SERVER_FAILURE |
static int |
REP_HOST_UNREACHABLE |
static int |
REP_NETWORK_UNREACHABLE |
static int |
REP_SUCCEEDED |
static int |
REP_TTL_EXPIRED |
static byte |
RESERVED
Reserved field.
|
static byte |
SOCKS_VERSION
Version of SOCKS protocol.
|
SOCKS_DEFAULT_PORT
Constructor and Description |
---|
Socks5(InetAddress inetAddress,
int port)
Constructs a Socks5 instance.
|
Socks5(SocketAddress socketAddress)
Constructs a Socks5 instance with a java.net.SocketAddress instance.
|
Socks5(SocketAddress socketAddress,
String username,
String password)
Constructs a Socks5 instance.
|
Socks5(SocksProxy chainProxy,
SocketAddress socketAddress) |
Socks5(String host,
int port)
Constructs a Socks5 instance.
|
Socks5(String host,
int port,
Credentials credentials)
Constructs a Socks instance.
|
Modifier and Type | Method and Description |
---|---|
Socket |
accept()
When binded server has income connection, this method will read second response message from
SOCKS server.
|
void |
buildConnection()
Connect SOCKS server using SOCKS protocol.
|
SocksProxy |
copy()
This method can create a same SocksProxy instance.
|
SocksProxy |
copyWithoutChainProxy()
Copy the
SocksProxy . |
Socket |
createProxySocket()
Creates a unconnected socket.
|
Socket |
createProxySocket(InetAddress address,
int port)
Creates a proxy socket.
|
List<SocksMethod> |
getAcceptableMethods()
Gets clent's acceptable methods.
|
SocksProxy |
getChainProxy()
Returns the chain proxy.
|
Credentials |
getCredentials()
Gets credentials from the SocksProxy.
|
InetAddress |
getInetAddress()
Get SOCKS server's address as IPv4 or IPv6.
|
InputStream |
getInputStream()
Gets InputStream from the socket that connected SOCKS server.
|
OutputStream |
getOutputStream()
Gets OutputStream from the socket that connected SOCKS server.
|
int |
getPort()
Get SOCKS Server port.
|
Socket |
getProxySocket()
Get the socket which connect SOCKS server.
|
SocksMethodRequestor |
getSocksMethodRequestor()
Gets
SocksMethodRequestor . |
int |
getSocksVersion()
Gets version of SOCKS protocol.
|
boolean |
isAlwaysResolveAddressLocally() |
CommandReplyMesasge |
requestBind(InetAddress inetAddress,
int port)
This method will send a BIND command to SOKCS server.
|
CommandReplyMesasge |
requestBind(String host,
int port)
This method will send a BIND command to SOKCS server.
|
CommandReplyMesasge |
requestConnect(InetAddress address,
int port)
This method will send a CONNECT command to SOCKS server and ask SOCKS server to connect remote
server.
|
CommandReplyMesasge |
requestConnect(SocketAddress address)
This method will send a CONNECT command to SOCKS server and ask SOCKS server to connect remote
server.
|
CommandReplyMesasge |
requestConnect(String host,
int port)
This method will send a CONNECT command to SOCKS server and ask SOCKS server to connect remote
server.
|
CommandReplyMesasge |
requestUdpAssociat(InetAddress address,
int port)
This method will send a UDP ASSOCIAT command to SOCKS server and ask SOCKS server to establish
a relay server.
|
CommandReplyMesasge |
requestUdpAssociat(String host,
int port)
This method will send a UDP ASSOCIAT command to SOCKS server and ask SOCKS server to establish
a relay server.
|
Socks5 |
setAcceptableMethods(List<SocksMethod> acceptableMethods)
Sets client's acceptable methods.
|
Socks5 |
setAlwaysResolveAddressLocally(boolean alwaysResolveAddressLocally) |
SocksProxy |
setChainProxy(SocksProxy chainProxy)
Returns the instance of
SocksProxy . |
Socks5 |
setCredentials(Credentials credentials)
Sets credentials.
|
Socks5 |
setHost(String host)
Set SOCKS server's host.
|
Socks5 |
setInetAddress(InetAddress inetAddress)
Sets SOCKS5 proxy server's IP address.
|
Socks5 |
setPort(int port)
Set SOCKS server port.
|
Socks5 |
setProxySocket(Socket proxySocket)
Set a unconnected socket which will be used to connect SOCKS server.
|
Socks5 |
setSocksMethodRequestor(SocksMethodRequestor requestor)
Sets
SocksMethodRequestor . |
String |
toString() |
protected static final org.slf4j.Logger logger
public static final byte SOCKS_VERSION
public static final byte RESERVED
public static final int REP_SUCCEEDED
public static final int REP_GENERAL_SOCKS_SERVER_FAILURE
public static final int REP_CONNECTION_NOT_ALLOWED_BY_RULESET
public static final int REP_NETWORK_UNREACHABLE
public static final int REP_HOST_UNREACHABLE
public static final int REP_CONNECTION_REFUSED
public static final int REP_TTL_EXPIRED
public static final int REP_COMMAND_NOT_SUPPORTED
public static final int REP_ADDRESS_TYPE_NOT_SUPPORTED
public static final byte AUTHENTICATION_SUCCEEDED
public Socks5(SocketAddress socketAddress, String username, String password)
socketAddress
- SOCKS5 server's address.username
- Username of the authentication.password
- Password of the authentication.public Socks5(String host, int port) throws UnknownHostException
host
- SOCKS5's server host.port
- SOCKS5's server port.UnknownHostException
- If the host can't be resolved.public Socks5(InetAddress inetAddress, int port)
inetAddress
- SOCKS5 server's address.port
- SOCKS5 server's port.public Socks5(SocketAddress socketAddress)
socketAddress
- SOCKS5 server's address.public Socks5(SocksProxy chainProxy, SocketAddress socketAddress)
public Socks5(String host, int port, Credentials credentials) throws UnknownHostException
host
- SOCKS5 server's host.port
- SOCKS5 server's port.credentials
- credentials.UnknownHostException
- If the host can't be resolved.public void buildConnection() throws SocksException, IOException
SocksProxy
This method will ask SOCKS server to select a method from the methods listed by client. If
SOCKS server need authentication, it will do authentication. If SOCKS server select 0xFF,It
means that none of the methods listed by the client are acceptable and this method should throw
SocksException
.
buildConnection
in interface SocksProxy
SocksException
- if any error about SOCKS protocol occurs.IOException
- if any IO error occurs.public CommandReplyMesasge requestConnect(String host, int port) throws SocksException, IOException
SocksProxy
requestConnect
in interface SocksProxy
host
- Remote server's host.port
- Remote server's port.SocksException
- If any error about SOCKS protocol occurs.IOException
- if any I/O error occurs.public CommandReplyMesasge requestConnect(InetAddress address, int port) throws SocksException, IOException
SocksProxy
requestConnect
in interface SocksProxy
address
- Remote server's address as java.net.InetAddress instance.port
- Remote server's port.SocksException
- If any error about SOCKS protocol occurs.IOException
- If any I/O error occurs.public CommandReplyMesasge requestConnect(SocketAddress address) throws SocksException, IOException
SocksProxy
requestConnect
in interface SocksProxy
address
- Remote server's address as java.net.SocketAddress instance.SocksException
- If any error about SOCKS protocol occurs.IOException
- If any I/O error occurs.public CommandReplyMesasge requestBind(String host, int port) throws SocksException, IOException
SocksProxy
requestBind
in interface SocksProxy
host
- Remote server's host.port
- Remote server's port.SocksException
- If any error about SOCKS protocol occurs.IOException
- If any I/O error occurs.public CommandReplyMesasge requestBind(InetAddress inetAddress, int port) throws SocksException, IOException
SocksProxy
requestBind
in interface SocksProxy
inetAddress
- Remote server's IP address.port
- Remote server's port.SocksException
- If any error about SOCKS protocol occurs.IOException
- If any I/O error occurs.public Socket accept() throws SocksException, IOException
SocksProxy
accept
in interface SocksProxy
SocksException
- If any error about SOCKS protocol occurs.IOException
- If any I/O error occurs.public CommandReplyMesasge requestUdpAssociat(String host, int port) throws SocksException, IOException
SocksProxy
requestUdpAssociat
in interface SocksProxy
host
- Remote UDP server's host.port
- Remote UDP server's port.SocksException
- If any error about SOCKS protocol occurs.IOException
- If any I/O error occurs.public CommandReplyMesasge requestUdpAssociat(InetAddress address, int port) throws SocksException, IOException
SocksProxy
requestUdpAssociat
in interface SocksProxy
address
- Remote UDP server's address.port
- Remote UDP server's port.SocksException
- If any error about SOCKS protocol occurs.IOException
- If any I/O error occurs.public int getPort()
SocksProxy
getPort
in interface SocksProxy
public Socks5 setPort(int port)
SocksProxy
setPort
in interface SocksProxy
port
- SOCKS server's port.public Socket getProxySocket()
SocksProxy
getProxySocket
in interface SocksProxy
public Socks5 setProxySocket(Socket proxySocket)
SocksProxy
setProxySocket
in interface SocksProxy
proxySocket
- a unconnected socket.public InputStream getInputStream() throws IOException
SocksProxy
getInputStream
in interface SocksProxy
IOException
- if any I/O error occurs.public OutputStream getOutputStream() throws IOException
SocksProxy
getOutputStream
in interface SocksProxy
IOException
- if any I/O error occurs.public Socks5 setAcceptableMethods(List<SocksMethod> acceptableMethods)
SocksProxy
setAcceptableMethods
in interface SocksProxy
acceptableMethods
- methods.public List<SocksMethod> getAcceptableMethods()
SocksProxy
getAcceptableMethods
in interface SocksProxy
public Socks5 setCredentials(Credentials credentials)
SocksProxy
setCredentials
in interface SocksProxy
credentials
- Credentials
instance.UsernamePasswordCredentials
,
AnonymousCredentials
public Credentials getCredentials()
SocksProxy
getCredentials
in interface SocksProxy
Credentials
instance.public Socks5 setSocksMethodRequestor(SocksMethodRequestor requestor)
SocksProxy
SocksMethodRequestor
.setSocksMethodRequestor
in interface SocksProxy
requestor
- SocksMethodRequestor
public SocksMethodRequestor getSocksMethodRequestor()
SocksProxy
SocksMethodRequestor
.getSocksMethodRequestor
in interface SocksProxy
SocksMethodRequestor
.public SocksProxy copy()
SocksProxy
The new instance created by this method has the same properties with the original instance, but they have different socket instance. The new instance's socket is also unconnected.
copy
in interface SocksProxy
public SocksProxy copyWithoutChainProxy()
SocksProxy
SocksProxy
. It will copy all properties of the
SocksProxy
but without chain proxy.copyWithoutChainProxy
in interface SocksProxy
public int getSocksVersion()
SocksProxy
getSocksVersion
in interface SocksProxy
public SocksProxy getChainProxy()
SocksProxy
getChainProxy
in interface SocksProxy
public SocksProxy setChainProxy(SocksProxy chainProxy)
SocksProxy
SocksProxy
.setChainProxy
in interface SocksProxy
chainProxy
- chain proxy.SocksProxy
.public Socks5 setHost(String host) throws UnknownHostException
SocksProxy
setHost
in interface SocksProxy
host
- SOCKS server's host.UnknownHostException
- if host can't resolve to InetAddress
public InetAddress getInetAddress()
SocksProxy
getInetAddress
in interface SocksProxy
public Socket createProxySocket(InetAddress address, int port) throws IOException
SocksProxy
createProxySocket
in interface SocksProxy
address
- address.port
- port.IOException
- If an I\O error occurred.public Socket createProxySocket() throws IOException
SocksProxy
createProxySocket
in interface SocksProxy
IOException
public Socks5 setInetAddress(InetAddress inetAddress)
inetAddress
- IP address of SOCKS5 proxy server.Socks5
.public boolean isAlwaysResolveAddressLocally()
public Socks5 setAlwaysResolveAddressLocally(boolean alwaysResolveAddressLocally)
Copyright © 2015. All rights reserved.