check response of the other machine

This commit is contained in:
2018-06-18 10:03:27 +02:00
parent 2bcd6c35b0
commit 2b9928329b
2 changed files with 45 additions and 0 deletions

21
python/client.py Executable file
View File

@ -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()

24
python/server.py Executable file
View File

@ -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()