66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
#!/usr/bin/env python
|
|
|
|
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):
|
|
|
|
def __init__(self,ip,port,clientsocket):
|
|
threading.Thread.__init__(self)
|
|
self.ip = ip
|
|
self.port = port
|
|
self.csocket = clientsocket
|
|
print("[+] New thread started for ",ip,":",str(port))
|
|
|
|
|
|
def run(self):
|
|
print("Connection from : ",ip,":",str(port))
|
|
|
|
# clientsock.send("\nWelcome to the server\n\n")
|
|
self.csocket.send("\nWelcome to the server\n\n".encode('utf-8'))
|
|
|
|
data = "dummydata"
|
|
|
|
while len(data):
|
|
data = self.csocket.recv(2048)
|
|
print("Client(%s:%s) sent : %s"%(self.ip, str(self.port), data))
|
|
response="You sent me : "+str(data)
|
|
self.csocket.send(response.encode('utf-8'))
|
|
|
|
print("Client at ",self.ip," disconnected...")
|
|
|
|
host = "0.0.0.0"
|
|
port = 9999
|
|
|
|
tcpsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
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()
|
|
if ip in parameter["allowed_ip"]:
|
|
newthread = ClientThread(ip, port, clientsock)
|
|
newthread.start()
|
|
else:
|
|
clientsock.close()
|
|
print("Denied Access from ",ip)
|