Skip to content

Instantly share code, notes, and snippets.

@ldx
Created March 18, 2015 00:18
Show Gist options
  • Save ldx/75e6f260fb61aa9ea769 to your computer and use it in GitHub Desktop.
Save ldx/75e6f260fb61aa9ea769 to your computer and use it in GitHub Desktop.
pyopenssl
from OpenSSL import SSL
import sys
import os
import socket
def verify_cb(conn, cert, errnum, depth, ok):
print 'Got certificate: %s' % cert.get_subject()
return ok
if len(sys.argv) < 3:
print 'Usage: python[2] client.py HOST PORT'
sys.exit(1)
dir = os.path.dirname(sys.argv[0])
if dir == '':
dir = os.curdir
# Initialize context
ctx = SSL.Context(SSL.SSLv23_METHOD)
ctx.set_verify(SSL.VERIFY_NONE, verify_cb)
# Set up client
sock = SSL.Connection(ctx, socket.socket(socket.AF_INET, socket.SOCK_STREAM))
sock.connect((sys.argv[1], int(sys.argv[2])))
sock.send('GET / HTTP/1.1\r\nHost: saucelabs.com\r\n\r\n')
while True:
try:
sys.stdout.write(sock.recv(1024))
sys.stdout.flush()
except SSL.Error as e:
print 'Connection died unexpectedly', e
break
sock.shutdown()
sock.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment