So I have an apache web server installed on a vm. I want to write a simple script that will get the home page of the website using a socket. I was able to do it without ssl, but I recently installed ssl and thought I should try using the ssl version. This is the code I have, based off of another question Opening a SSL socket connection in Python
import socket, ssl
s = socket.socket()
wrappedSocket = ssl.wrap_socket(s)
wrappedSocket.connect(('127.0.0.1', 443))
wrappedSocket.sendall(
'GET / HTTP/1.1\r\n'
'Host: vulnerable\r\n'
'User-Agent: sslsocket.py\r\n'
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n'
'Accept-Language: en-US,en;q=0.5\r\n'
'Accept-Encoding: gzip, deflate\r\n'
'Connection: keep-alive\r\n'
'\r\n'
)
ans = wrappedSocket.recv(4096)
print ans
The script keeps on running and never outputs anything. Upon further debugging, I found out it breaks on the connect() function call, but am unable to figure out why it happens.
Edit- After some help in the comments, I realised that the domain name is 127.0.1.1. However, now I get the HTTP headers as output, but it doesn't actually give me the HTML of the page. What is wrong this time?