From ae109055b9c775a04990cae45ba13ec94ca2aac8 Mon Sep 17 00:00:00 2001 From: ademant Date: Fri, 8 Nov 2019 21:29:47 +0100 Subject: [PATCH] small changes to myserver --- myserver.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/myserver.py b/myserver.py index 46c9d98..612908f 100644 --- a/myserver.py +++ b/myserver.py @@ -1,6 +1,23 @@ #!/usr/bin/env python -import socket, threading +import requests,threading,time,json,zlib,gnupg,socket,psutil,os,sys,pymysql,queue,numpy +gpg=gnupg.GPG() + +pathname = os.path.dirname(sys.argv[0]) +abspath=os.path.abspath(pathname) +configfile=abspath+"/config.json" +try: + cf=open(configfile,"r") +except: + cf=open(configfile+".template","r") + +log_conf=json.load(cf) +cf.close() + +parameter={"device":socket.gethostname(),"allowed_ip":{"127.0.0.1":"25A4CF79414F10FD"},"gpg_keyid":"25A4CF79414F10FD"} +for n in parameter: + if n in log_conf: + parameter[n]=log_conf[n] class ClientThread(threading.Thread): @@ -36,12 +53,13 @@ tcpsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) tcpsock.bind((host,port)) - - while True: tcpsock.listen(4) print("\nListening for incoming connections...") (clientsock, (ip, port)) = tcpsock.accept() - newthread = ClientThread(ip, port, clientsock) - newthread.start() - + if ip in parameter["allowed_ip"]: + newthread = ClientThread(ip, port, clientsock) + newthread.start() + else: + clientsock.close() + print("Denied Access from ",ip)