Created
September 26, 2015 10:26
-
-
Save kaskavalci/aace72b5336cf7330249 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
httpRequest = """ | |
GET /index.html HTTP/1.1 | |
Accept-Encoding: identity | |
Host: #Your IP Address | |
Connection: close | |
User-Agent: Python | |
""" | |
try: | |
#Create the socket | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
#Set timeout to some seconds, 2 in this case. Don't wait forever if server doesn't respond. | |
s.settimeout(2) | |
#Connect to your host | |
s.connect(("google.com",80)) | |
#Send HTTP request | |
s.send(httpRequest) | |
#Get the response | |
data = (s.recv(4096)) | |
#Enjoy your response! | |
print data | |
#Close the socket when done | |
s.close() | |
except Exception, e: | |
print "Error communicating with host.", sys.exc_info()[0] | |
sys.exit(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment