Bootstrap FreeKB - OpenSSL - Test connection to host and port
OpenSSL - Test connection to host and port

Updated:   |  OpenSSL articles

The OpenSSL command with the s_client -connect option can be used to test connection to a host on a port. 

If using Linux, the which command can be used to determine if OpenSSL is installed on the system. If not, refer to Install OpenSSL on Linux.

~]# which openssl
/usr/bin/openssl

 

If using Windows, let's say OpenSSL is installed at this location. Or, refer to Install OpenSSL on Windows.

cd "C:\program files\gnuwin32\bin\"

 

Start OpenSSL:

openssl.exe

 

The following examples are based on Linux, but will work the same with OpenSSL on Windows.

If the hostname is invalid, something like this should be returned.

~]# openssl s_client -connect bogus.example.com:80
140368544307008:error:2008F002:BIO routines:BIO_lookup_ex:system lib:crypto/bio/b_addr.c:730:Name or service not known
connect:errno=2

 

If the hostname is valid but connections to the host on the port are not allowed, something like this should be returned.

~]# openssl s_client -connect www.example.com:12345
140335663650624:error:02002071:system library:connect:No route to host:crypto/bio/b_sock2.c:110:
140335663650624:error:2008A067:BIO routines:BIO_connect:connect error:crypto/bio/b_sock2.c:111:
connect:errno=113

 

errno=9 often suggests the connection timed out, perhaps because there is a firewall refusing the connection.

~]# openssl s_client -connect www.example.com:98765
socket: Bad file descriptor
connect:errno=9

 

If the connection is successful, both CONNECTED and return code: 0 (ok) should be included in the output.

~]$ openssl s_client -connect mx1.example.com:25
CONNECTED(00000003)
Verify return code: 0 (ok)

 

If the connection hangs indefinitely and never returns any stdout or stderr you can instead try using cURL with the -v (verbose) flag.

~]$ curl --insecure https://www.example.com:12345/ -v
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 10.11.12.13...
* TCP_NODELAY set
  0     0    0     0    0     0      0      0 --:--:--  0:02:10 --:--:--     0* connect to 10.11.12.13 port 12345 failed: Connection timed out
* Failed to connect to www.example.com port 12345: Connection timed out
* Closing connection 0
curl: (7) Failed to connect to www.example.com port 12345: Connection timed out
command terminated with exit code 7

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 197f13 in the box below so that we can be sure you are a human.