Skip to content

Instantly share code, notes, and snippets.

@jstnlvns
Forked from 4ndrej/SSLPoke.java
Last active August 29, 2015 14:24
Show Gist options
  • Save jstnlvns/0670d8c6bf4beb81dfa3 to your computer and use it in GitHub Desktop.
Save jstnlvns/0670d8c6bf4beb81dfa3 to your computer and use it in GitHub Desktop.
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.*;
/** Establish a SSL connection to a host and port, writes a byte and
* prints the response. See
* http://confluence.atlassian.com/display/JIRA/Connecting+to+SSL+services
*/
public class SSLPoke {
public static void main(String[] args) {
if (args.length != 2) {
System.out.println("Usage: "+SSLPoke.class.getName()+" <host> <port>");
System.exit(1);
}
try {
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket(args[0], Integer.parseInt(args[1]));
InputStream in = sslsocket.getInputStream();
OutputStream out = sslsocket.getOutputStream();
// Write a test byte to get a reaction :)
out.write(1);
while (in.available() > 0) {
System.out.print(in.read());
}
System.out.println("Successfully connected");
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
@jstnlvns
Copy link
Author

  1. Put into folder named SSLPoke.
  2. Put SSLPoke.java into folder
  3. Run javac SSLPoke.java - may need to install correct jdk to compile java file
  4. Once compile the file can be ran using java SSLPoke server port

mkdir SSLPoke
mv SSLPoke.java SSLPoke
javac SSLPoke.java
java SSLPoke server port

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment