Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import socket, ssl, re
  4.  
  5.  
  6. context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
  7.  
  8. context.verify_mode = ssl.CERT_REQUIRED
  9.  
  10. context.check_hostname = True
  11.  
  12. context.load_default_certs()
  13.  
  14.  
  15. hostname = 'www.gprc.ab.ca'
  16.  
  17.  
  18. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  19.  
  20. ssl_sock = context.wrap_socket(sock, server_hostname=hostname)
  21.  
  22. ssl_sock.connect((hostname, 443))
  23.  
  24.  
  25. course = 'cs3130'
  26.  
  27. url = 'https://{}/programs/courses/index.html?c_keyword=&c_code={}'
  28.  
  29. url = url.format(hostname, course)
  30.  
  31.  
  32. ssl_sock.sendall('GET {} HTTP/1.0\n\n'.format(url).encode('ascii'))
  33.  
  34.  
  35. content = ''
  36.  
  37. recv = ssl_sock.recv(2048).decode('ascii')
  38.  
  39. while not recv == '':
  40.  
  41.     content += recv
  42.  
  43.     recv = ssl_sock.recv(2048).decode('ascii')
  44.  
  45.  
  46.  
  47. print(content)
  48.  
  49.  
  50. ssl_sock.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement