def get_webserver_for_host(hostname: str, webservers: Counter): connection = socket.create_connection((hostname, 80), timeout=5) http_request_string = HTTP_REQUEST_TEMPLATE.format(hostname) connection.send(http_request_string.encode()) result = connection.recv(MAX_BYTES_TO_READ) server = detect_webserver_from_response(result) webservers[server] += 1 connection.close() print("Completed: {}".format(hostname))
def get_webserver_for_host(hostname: str, webservers: Counter): reader, writer = yield from asyncio.open_connection(host=hostname, port=80) http_request_string = HTTP_REQUEST_TEMPLATE.format(hostname) writer.write(http_request_string.encode()) response = yield from reader.read(MAX_BYTES_TO_READ) server = detect_webserver_from_response(response) webservers[server] += 1 writer.close() print("Completed: {}".format(hostname))
async def get_webserver_for_host(hostname: str, webservers: Counter): reader, writer = await asyncio.open_connection(host=hostname, port=80) http_request_string = HTTP_REQUEST_TEMPLATE.format(hostname) writer.write(http_request_string.encode()) response = await reader.read(MAX_BYTES_TO_READ) server = detect_webserver_from_response(response) webservers[server] += 1 writer.close() print("Completed: {}".format(hostname))
def get_webserver_for_host(hostname: str, webservers: Counter): try: reader, writer = yield from asyncio.wait_for(asyncio.open_connection(host=hostname, port=80), timeout=TIMEOUT) http_request_string = HTTP_REQUEST_TEMPLATE.format(hostname) writer.write(http_request_string.encode()) response = yield from asyncio.wait_for(reader.read(MAX_BYTES_TO_READ), timeout=TIMEOUT) server = detect_webserver_from_response(response) webservers[server] += 1 writer.close() print("Completed: {}".format(hostname)) except asyncio.TimeoutError: print("Timed out: {}".format(hostname))
def get_webserver_for_host(hostname: str, webservers: Counter): try: reader, writer = yield from asyncio.wait_for(asyncio.open_connection( host=hostname, port=80), timeout=TIMEOUT) http_request_string = HTTP_REQUEST_TEMPLATE.format(hostname) writer.write(http_request_string.encode()) response = yield from asyncio.wait_for(reader.read(MAX_BYTES_TO_READ), timeout=TIMEOUT) server = detect_webserver_from_response(response) webservers[server] += 1 writer.close() print("Completed: {}".format(hostname)) except asyncio.TimeoutError: print("Timed out: {}".format(hostname))