update
This commit is contained in:
85
client.py
85
client.py
@@ -2,6 +2,44 @@
|
||||
import argparse
|
||||
import logging
|
||||
import sys
|
||||
import socket
|
||||
|
||||
FORMAT = 'utf-8'
|
||||
BUFSIZE = 4096
|
||||
|
||||
|
||||
def receive_bytes(client: socket.socket):
|
||||
buffering = True
|
||||
buffer = b''
|
||||
while buffering:
|
||||
received = client.recv(BUFSIZE)
|
||||
received_size = len(received)
|
||||
logging.debug("Received size: %s", received_size)
|
||||
logging.debug("Received: %r", received)
|
||||
|
||||
if received_size < BUFSIZE:
|
||||
buffering = False
|
||||
|
||||
buffer += received
|
||||
buffer_split = buffer.split(b"\r\n\r\n")
|
||||
buffer = buffer_split[-1]
|
||||
|
||||
for part in buffer_split[:-1]:
|
||||
yield part + b"\r\n\r\n"
|
||||
|
||||
if buffer:
|
||||
yield buffer
|
||||
|
||||
def http_parser(client: socket.socket):
|
||||
headers = {}
|
||||
start_line = ""
|
||||
|
||||
counter = 0
|
||||
for received in receive_bytes(client):
|
||||
if counter == 0:
|
||||
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='HTTP Client')
|
||||
@@ -13,13 +51,52 @@ def main():
|
||||
arguments = parser.parse_args()
|
||||
|
||||
logging.basicConfig(level=logging.ERROR - (10 * arguments.verbose))
|
||||
logging.debug("Arguments: %r", arguments)
|
||||
raise Exception("dsfgsfsd")
|
||||
logging.debug("Arguments: %s", arguments)
|
||||
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
client.connect((arguments.URI, arguments.port))
|
||||
|
||||
message = "GET /httpgallery/chunked/chunkedimage.aspx HTTP/1.1\r\nHost: www.httpwatch.com:80\r\n\r\n".encode(FORMAT)
|
||||
client.sendall(message)
|
||||
|
||||
tmp = b''
|
||||
keep = False
|
||||
count = 0
|
||||
for line in receive_lines(client):
|
||||
|
||||
if count > 0:
|
||||
tmp += line.rstrip(b"\r\n")
|
||||
if keep:
|
||||
count += 1
|
||||
|
||||
if line == b'\r\n':
|
||||
keep = True
|
||||
|
||||
logging.debug('end of part 1')
|
||||
|
||||
logging.debug("attempt 2")
|
||||
while True:
|
||||
logging.debug("attempt")
|
||||
keep = False
|
||||
for line in receive_lines(client):
|
||||
if line == b"0\r\n":
|
||||
break
|
||||
if keep:
|
||||
tmp += line.rstrip(b"\r\n")
|
||||
keep = True
|
||||
|
||||
if b"0\r\n" == line:
|
||||
break
|
||||
logging.debug("content: %s", tmp)
|
||||
# logging.debug("content: %r", tmp.replace(b"\r\n", b"").decode("utf-8"))
|
||||
|
||||
f = open("test.jpeg", "wb")
|
||||
f.write(tmp)
|
||||
|
||||
|
||||
try:
|
||||
main()
|
||||
except Exception as e:
|
||||
print("[ABRT] Internal error: "+str(e), file=sys.stderr)
|
||||
print("[ABRT] Internal error: " + str(e), file=sys.stderr)
|
||||
logging.debug("Internal error", exc_info=e)
|
||||
sys.exit(70)
|
||||
sys.exit(70)
|
||||
|
Reference in New Issue
Block a user