From 8ff97d2a65eff7a38caf1863f7150047a45b7bc0 Mon Sep 17 00:00:00 2001 From: facat Date: Tue, 18 Jun 2019 17:50:50 +0800 Subject: [PATCH] =?UTF-8?q?1.=E7=AC=AC=E4=B8=80=E6=AC=A1=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + main.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 .gitignore create mode 100644 main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ceb386 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +venv diff --git a/main.py b/main.py new file mode 100644 index 0000000..cc786eb --- /dev/null +++ b/main.py @@ -0,0 +1,20 @@ +from socketserver import BaseRequestHandler, TCPServer + + +class EchoHandler(BaseRequestHandler): + def handle(self): + print("Got connection from", self.client_address) + host=self.request.recv(1024) + print("Host is {host}".format(host=host)) + if host: + if host=='bwg'.encode('ascii'): + self.request.sendall("50%\n".encode('ascii')) + print('send to bwg') + if host=='hosteons'.encode('ascii'): + self.request.sendall("80%\n".encode('ascii')) + self.request.close() + + +if __name__ == "__main__": + serv = TCPServer(("", 20000), EchoHandler) + serv.serve_forever()