FlaskTelnetGeo
Verfasst: Mittwoch 20. Januar 2016, 12:57
Code: Alles auswählen
from telnetlib import Telnet
import time
def httpRequest(host, path='/', port=80): #default wird wurzel '/' angesprochen
starttime = time.time()
connection = Telnet(host, port)
connection.write('GET '+path+' HTTP/1.1\r\n')
connection.write('Host: '+host+'\r\n')
connection.write('Connection: close\r\n')
connection.write('\r\n')
response = connection.read_all()
endtime = time.time()
index = response.find('\r\n\r\n')
return (response[:index], response[index:], endtime-starttime) #0:head, 1:body, 2:endtime-starttime