From b7cf20cea38f28f1f488e2667ea43ee579c0ed95 Mon Sep 17 00:00:00 2001 From: sc0tfree Date: Sun, 18 Jun 2017 19:02:23 -0400 Subject: [PATCH] Add test server to demo functionality --- testserver.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 testserver.py diff --git a/testserver.py b/testserver.py new file mode 100644 index 0000000..4d99fb4 --- /dev/null +++ b/testserver.py @@ -0,0 +1,66 @@ +#!/usr/bin/python + +# Author: sc0tfree +# Twitter: @sc0tfree +# Email: henry@sc0tfree.com + +import os +import socket + + +def generate_random_hex(length): + ''' + Generates a hex string of arbitrary length - 1, ending in a newline. + ''' + hex_string = os.urandom(length - 1) + hex_string += '\x0a' + return hex_string + + +host = '127.0.0.1' +port = 12345 + +s = socket.socket() + +s.bind((host, port)) + +s.listen(5) + +try: + + while True: + + c, addr = s.accept() + + print 'Connection established from', addr[0], ':', addr[1] + + c.send('Hello from Test Server\n') + + # Echo Test + c.send('Echo Test - enter string:') + data = c.recv(1024) + print 'Echo Test - received: ', data + c.send('Echo Test - received: ' + data + '\n') + + # Hex Test + c.send('Hex Test - enter length:') + data = c.recv(1024) + + try: + hex_length = int(data) + except ValueError: + c.send('You must enter a number. Defaulting to 10.\n') + hex_length = 10 + + hex_string = generate_random_hex(hex_length) + c.send('Sending hex string...\n\n') + print 'Hex Test - sending: ', hex_string + c.send(hex_string) + + c.close() + print 'Closed connection to ', addr[0], ':', addr[1] + +except KeyboardInterrupt: + c.close() + print '\nExiting...' + exit(0)