From 2b9928329b125bd861dcce72bed899fbb7d3f452 Mon Sep 17 00:00:00 2001 From: Patrick Neumann Date: Mon, 18 Jun 2018 10:03:27 +0200 Subject: [PATCH] check response of the other machine --- python/client.py | 21 +++++++++++++++++++++ python/server.py | 24 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100755 python/client.py create mode 100755 python/server.py diff --git a/python/client.py b/python/client.py new file mode 100755 index 0000000..90b25d8 --- /dev/null +++ b/python/client.py @@ -0,0 +1,21 @@ +#!/usr/bin/python + +import socket +import hashlib +import time + +ip = "10.0.0.50" +port = 12345 +s = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) +s.connect(( ip, port )) + +try: + while True: + s.send( hashlib.sha256( socket.gethostbyname( socket.gethostname() ) ).hexdigest() ) + antwort = s.recv( 1024 ) + if antwort != hashlib.sha256( ip ).hexdigest(): + print "shutting down now..." + time.sleep(10) +finally: + s.close() + diff --git a/python/server.py b/python/server.py new file mode 100755 index 0000000..8ab4209 --- /dev/null +++ b/python/server.py @@ -0,0 +1,24 @@ +#!/usr/bin/python + +import socket +import hashlib + +ip = "10.0.0.50" +port = 12345 + +s = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) +s.bind(( ip, port )) +s.listen( 1 ) + +try: + while True: + komm, addr = s.accept() + while True: + data = komm.recv( 1024 ) + if not data: + komm.close() + break + antwort = ( hashlib.sha256( socket.gethostbyname( socket.gethostname() ) ).hexdigest() if hashlib.sha256( addr[0] ).hexdigest() == data else hashlib.sha256( "ERROR" ).hexdigest() ) + komm.send( antwort ) +finally: + s.close()