source: test/services/hasher.py @ 23

Last change on this file since 23 was 3, checked in by tim, 9 years ago

.

  • Property svn:executable set to *
File size: 1.0 KB
RevLine 
[3]1#!/usr/bin/env python3
2#
3# Copyright (C) 2015 Blindspot Security LLC
4# by Timothy D. Morgan
5# twits: @ecbftw
6
7import sys
8import time
9import hashlib
10import socketserver
11import http.server
12
13
14class HashHandler(http.server.BaseHTTPRequestHandler):
15    """
16    """
17
18    def do_GET(self):
19        resolution = time.clock_getres(time.CLOCK_MONOTONIC)
20
21        do_hash = False
22        if 't=' in self.path and self.path.split('t=', 1)[1] == '1':
23            do_hash = True
24
25        received = int(time.monotonic()/resolution)
26        if do_hash:
27            x = hashlib.md5(b'01234567').digest()
28        now = int(time.monotonic()/resolution)
29       
30        self.send_response(200)
31        self.send_header('Content-Type','text/plain; charset=UTF-8')
32        self.end_headers()
33
34        content = "waited: %d\n" % (now - received)
35        self.wfile.write(content.encode('utf-8'))
36        self.wfile.flush()
37
38
39if __name__ == "__main__":
40    HOST, PORT = "0.0.0.0", 3240
41    server = socketserver.TCPServer((HOST, PORT), HashHandler)
42    server.serve_forever()
Note: See TracBrowser for help on using the repository browser.