Skip to content

Instantly share code, notes, and snippets.

@radut
Forked from MatthewJDavis/SSLPoke.java
Created May 4, 2023 08:00
Show Gist options
  • Save radut/022cba3c43bade2472aae08087e59dc2 to your computer and use it in GitHub Desktop.
Save radut/022cba3c43bade2472aae08087e59dc2 to your computer and use it in GitHub Desktop.

Revisions

  1. @MatthewJDavis MatthewJDavis created this gist Jan 10, 2019.
    34 changes: 34 additions & 0 deletions SSLPoke.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    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();
    }
    }
    }