说明 |
java SSLPoke baidu.com 443
import java.io.*; import javax.net.ssl.*;
public class SSLPoke {
public SSLPoke() { }
public static void main(String args[]) { if(args.length != 2) { System.err.println("Utility to debug Java connections to SSL servers"); System.err.println("Usage: "); System.err.println((new StringBuilder()).append(" java ").append(SSLPoke.getName()).append(" <host> <port>").toString()); System.err.println("or for more debugging:"); System.err.println((new StringBuilder()).append(" java -Djavax.net.debug=ssl ").append(SSLPoke.getName()).append(" <host> <port>").toString()); System.err.println(); System.err.println("Eg. to test the SSL certificate at https://localhost, use"); System.err.println((new StringBuilder()).append(" java ").append(SSLPoke.getName()).append(" localhost 443").toString()); System.exit(1); } try { SSLSocketFactory sslsocketfactory = (SSLSocketFactory)SSLSocketFactory.getDefault(); SSLSocket sslsocket = (SSLSocket)sslsocketfactory.createSocket(args[0], Integer.parseInt(args[1])); InputStream inputstream = sslsocket.getInputStream(); OutputStream outputstream = sslsocket.getOutputStream(); outputstream.write(1); for(; inputstream.available() > 0; System.out.print(inputstream.read())); System.out.println("Successfully connected"); System.exit(0); } catch(SSLHandshakeException sslhandshakeexception) { if(sslhandshakeexception.getCause() != null) sslhandshakeexception.getCause().printStackTrace(); else sslhandshakeexception.printStackTrace(); } catch(Exception exception) { exception.printStackTrace(); } System.exit(1); } }
|