Ejemplo n.º 1
0
 def on_message(self, message):
     if not CBUtil.isJson(message): return
     msg = json.loads(message)
     me = SocketHandler.getConn(self.id)
     sid = -1
     if "sid" in msg:
         if not me.inSids(msg["sid"]):
             return
         sid = me.getSid(msg["sid"])
     SocketHandler.message(me, msg, sid)
Ejemplo n.º 2
0
 def on_message(self, message):
     if not CBUtil.isJson(message): return
     msg = json.loads(message)
     me = SocketHandler.getConn(self.id)
     sid = -1
     if "sid" in msg:
         if not me.inSids(msg["sid"]):
             return
         sid = me.getSid(msg["sid"])
     SocketHandler.message(me, msg, sid)
Ejemplo n.º 3
0
import SocketHandler
from SocketHandler import SocketHandler
from DataHandler import DataHandler
import sys

while True:
    dataHandler = DataHandler()
    ip = dataHandler.getRandom()

    if ip == "":
        print "Could not find any ips that need processing"
        sys.exit()

    print "Processing " + ip

    socksHandler = SocketHandler(ip)
    banner = socksHandler.grabBanner()

    #Yes I understand that this is an awful hack
    banner = banner.replace("'", "\'")

    try:
        dataHandler.setBanner(ip, banner)
    except:
        print "Saving banner for " + ip + " failed!"
Ejemplo n.º 4
0
def Client_Thread(ClientSocket, Address):
    myObj = SocketHandler.SocketHandler(ClientSocket, Address)
    myObj.EngageClient()
Ejemplo n.º 5
0
 def __init__(self):
     #self.socket = SocketHandler.SocketHandler()
     self.socket = SocketHandler.SocketHandler(C_PORT, S_ADDRESS, S_PORT)
     self.tick()
Ejemplo n.º 6
0
import SocketHandler as sh
import threading

if __name__ == '__main__':
    server = sh.SocketServer((sh.SocketHandler.HOST, sh.SocketHandler.PORT),
                             sh.SocketHandler)
    with server:
        ip, port = server.server_address
        print('Server initialised at {}:{}'.format(ip, port))
        #server_thread = threading.Thread(target=server.serve_forever)
        #server_thread.daemon = True
        try:
            #server_thread.start()
            #print('Server loop running in thread:', server_thread.name)
            server.serve_forever()
        except Exception:
            server.shutdown()
Ejemplo n.º 7
0
 def open(self, *args):
     connType = self.get_argument("type")
     token = ""
     if connType == "storager":
         token = self.get_argument("token")
     SocketHandler.open(connType, token, self)
Ejemplo n.º 8
0
 def on_close(self):
     obj = SocketHandler.getConn(self.id)
     SocketHandler.closeSids(obj)
     SocketHandler.removeConn(obj)
Ejemplo n.º 9
0
        # COMPUTE
        if len(incoming_message) != 2:
            print "Got wrong message:\n%s" % incoming_message  # OR send error to the messenger?
            # MAYBE add 1 more message -- "KILL_DQM" -- and stop DQM process with it?
            continue
        if incoming_message[0] == "NEW_FILENAME":
            try:
                (tdc_addr, filename) = incoming_message[1].split(':')
            except ValueError:
                print "Got invalid 'NEW_FILENAME' message value: %s" % (
                    incoming_message[1])
                continue
            print incoming_message[1], tdc_addr, filename
            result_filename = computation_process(filename)

        # SEND
        try:
            messenger_socket.Send("NEW_DQM_PLOT", result_filename)
        except SocketHandler.SendingError:
            #Send failed
            print 'Send failed'
            sys.exit()


if __name__ == '__main__':
    host = "localhost"
    socket_to_messenger = SocketHandler.SocketHandler(host, 1987)
    socket_to_messenger.Handshake(4)  # 4 = DQM
    run_dqm_process(socket_to_messenger)
Ejemplo n.º 10
0
import SocketHandler
from SocketHandler import SocketHandler
from DataHandler import DataHandler
import sys


while True:
	dataHandler = DataHandler()
	ip = dataHandler.getRandom()

	if ip == "":
		print "Could not find any ips that need processing"
		sys.exit()

	print "Processing "+ip

	socksHandler = SocketHandler(ip)
	banner = socksHandler.grabBanner()

	#Yes I understand that this is an awful hack
	banner = banner.replace("'","\'")

	try:
		dataHandler.setBanner(ip, banner)
	except:
		print "Saving banner for "+ip+" failed!"
Ejemplo n.º 11
0
 def open(self, *args):
     connType = self.get_argument("type")
     token = ""
     if connType == "storager":
         token = self.get_argument("token")
     SocketHandler.open(connType, token, self)
Ejemplo n.º 12
0
 def on_close(self):
     obj = SocketHandler.getConn(self.id)
     SocketHandler.closeSids(obj)
     SocketHandler.removeConn(obj)
Ejemplo n.º 13
0
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Button
import SocketHandler as sh
import ButtonHandler as bh
from sklearn.linear_model import LinearRegression
import pandas as pd
#创建上下两个图表
fig, axes = plt.subplots(2, 1)
ax1 = axes[0]
ax2 = axes[1]

#设置图形显示位置
plt.subplots_adjust(bottom=0.2)

socket = sh.SocketHandler()
socket.create_client()

#显示数据
socket.send_getdata_close()
dt = socket.pull_getdata()
while dt == None:
    socket.send_getdata_close()
    dt = socket.pull_getdata()

#ax2.scatter(0, min(dt) - 2)
#ax2.scatter(20, max(dt) + 2)
l2, = ax2.plot(range(0, len(dt)), dt)

#多加一个数据用来预测
print('dt len:', len(dt))