Exemple #1
0
    def __init__ (self,
        host = None,
        port = 23,
        readCallback = None,
        stateCallback = None,
    ):
        """Create a telnet connection.

        Inputs:
            readCallback: function to call whenever a line of data is read;
                it will be sent one argument: the line of data
            stateCallback: function to call whenever the socket
                connects or disconnected; it will be sent two arguments:
                    is connected flag (true if connected, false if not)
                    this connection object      
        """
        TCPConnection.__init__(self,
            host=host,
            port=port,
            readCallback=readCallback,
            stateCallback=stateCallback,
            readLines = True,
            authReadCallback = self._authRead,
            authReadLines = False,
        )
        
        self._initData()
Exemple #2
0
def getTrace(visit_file, direction=None):
    with open(visit_file, 'r') as f:
        sample = json.load(f)

    Config.hostname.update(sample[u'ip_to_name'])
    webId, traceId = sample['visit_log'][u'current_url'], sample['visit_log']['visit_id']
    
    trace = Trace(traceId, webId)
    for tcp_conn in sample['tcp_connections']:
        
        connection_id = tcp_conn['connection_id']
        
        TCP = TCPConnection(connection_id, webId, hostip=sample['visit_log'][u'host_ip'])

        for pkt in tcp_conn['packets']:
            pkt_time, pkt_size = pkt[0], abs(pkt[1])
            
            if pkt_size == 0:
                continue

            pkt_dir = Packet.Outgoing if pkt[1] < 0 else Packet.Incoming

            if direction is None or direction == pkt_dir:
                TCP.addPacket(Packet(pkt_time, pkt_size, pkt_dir))
        TCP._packets.sort(key=lambda x: x.getTime())
        trace.addTcpCon(TCP)
    
    return trace
Exemple #3
0
    def __init__ (self,
        host = None,
        port = 9877,
        readCallback = None,
        stateCallback = None,
        loginExtra = None,
        name = "",
    ):
        """Create a hub connection, but do not connect

        Inputs:
        - host: default TCP address of host (can override when connecting)
        - port: default TCP port (can override when connecting);
            defaults to 9877, the standard hub port
        - readCallback: function to call whenever a line of data is read;
          it will be sent two arguments: (self, readData);
          the read data does not include the line terminator
        - stateCallback: function to call whenever the state of the connection changes;
          it will be sent one argument: self
        - loginExtra: additional string to be sent with the login command.
        """
        TCPConnection.__init__(self,
            host=host,
            port=port,
            readCallback = readCallback,
            readLines = True,
            stateCallback = stateCallback,
            authReadCallback = self._authRead,
            authReadLines = True,
            name = name,
        )
        self._initData()
        self._loginExtra = loginExtra
Exemple #4
0
    def __init__(
        self,
        host=None,
        port=9877,
        readCallback=None,
        stateCallback=None,
        loginExtra=None,
        name="",
    ):
        """Create a hub connection, but do not connect

        Inputs:
        - host: default TCP address of host (can override when connecting)
        - port: default TCP port (can override when connecting);
            defaults to 9877, the standard hub port
        - readCallback: function to call whenever a line of data is read;
          it will be sent two arguments: (self, readData);
          the read data does not include the line terminator
        - stateCallback: function to call whenever the state of the connection changes;
          it will be sent one argument: self
        - loginExtra: additional string to be sent with the login command.
        """
        TCPConnection.__init__(
            self,
            host=host,
            port=port,
            readCallback=readCallback,
            readLines=True,
            stateCallback=stateCallback,
            authReadCallback=self._authRead,
            authReadLines=True,
            name=name,
        )
        self._initData()
        self._loginExtra = loginExtra
Exemple #5
0
class Test(unittest.TestCase):
    def setUp(self):
        self.tcp = TCPConnection()

    def test_init_TCPConnection(self):
        self.assertTrue(isinstance(self.tcp.state, TCPClosed))

    def test_change_state(self):
        self.tcp.change_state(TCPEstablished())
        self.assertTrue(isinstance(self.tcp.state, TCPEstablished))

    def test_open(self):
        self.tcp.open()
        self.assertTrue(isinstance(self.tcp.state, TCPEstablished))
Exemple #6
0
class Test(unittest.TestCase):

    def setUp(self):
        self.tcp = TCPConnection()

    def test_init_TCPConnection(self):
        self.assertTrue(isinstance(self.tcp.state, TCPClosed))

    def test_change_state(self):
        self.tcp.change_state(TCPEstablished())
        self.assertTrue(isinstance(self.tcp.state, TCPEstablished))

    def test_open(self):
        self.tcp.open()
        self.assertTrue(isinstance(self.tcp.state, TCPEstablished))        
Exemple #7
0
    def connect (self,
        username,
        password,
        host = None,
        port = None,
    ):
        """Open the connection and log in.

        Inputs:
            host: IP address (name or numeric) of host
            username: username for login
            password: password for login
        """
        self._initData()
        self._password = password
        self._username = username

        TCPConnection.connect(self, host, port)
Exemple #8
0
 def connect (self,
     progID,
     password,
     username,
     host = None,
     port = None,
 ):
     """Opens the connection and logs in.
     Inputs:
     - progID: the desired program ID; the actual program ID
         should be the same except case may differ
     - password: the password associated with the program ID
     - username: desired username; the actual username should match if unique,
         else the hub will modify it in some fashion
     - host: TCP address of host; overrides the default specified at instantiation
     - port: TCP port of host; overrides the default specified at instantiation
     """
     # make the basic connection
     self._initData()
     self.desProgID = progID
     self.__password = password
     self.desUsername = username
     TCPConnection.connect(self, host, port)
Exemple #9
0
 def connect(
     self,
     progID,
     password,
     username,
     host=None,
     port=None,
 ):
     """Opens the connection and logs in.
     Inputs:
     - progID: the desired program ID; the actual program ID
         should be the same except case may differ
     - password: the password associated with the program ID
     - username: desired username; the actual username should match if unique,
         else the hub will modify it in some fashion
     - host: TCP address of host; overrides the default specified at instantiation
     - port: TCP port of host; overrides the default specified at instantiation
     """
     # make the basic connection
     self._initData()
     self.desProgID = progID
     self.__password = password
     self.desUsername = username
     TCPConnection.connect(self, host, port)
Exemple #10
0
class RelayStation():
    def __init__(self):
        self.conn = TCPConnection(self.callback)
    
    def connect(self):    
        self.conn.createServer(port = 4000)
        
    def close_conn(self):
        self.conn.closeConnection()

    def callback(self, pck):
        print "Received new packet: " + repr(pck.read_float_list())
        raw_input()
        out = Packet()
        out.put_float_list(pck.read_float_list())
        print "Sending packet back "
        self.conn.sendPacket(out)
        print "Done."
Exemple #11
0
class SendingStation():
    def __init__(self):
        self.conn = TCPConnection(self.callback)
    
    def connect(self):    
        address = "192.168.235.6"
        self.conn.createClient(address, 5000)
        while True:
            pck = Packet()
            dat = [random.random() for _ in range(10)]
            pck.put_float_list(dat)
            print "Sending: " + repr(dat)
            self.conn.sendPacket(pck)
            raw_input()
        
    def close_conn(self):
        self.conn.closeConnection()

    def callback(self, pck):
        print "Received!"
        print "Received new packet: " + repr(pck.read_float_list())
Exemple #12
0
 def __init__(self):
     self.conn = TCPConnection(self.callback)
Exemple #13
0
 def _setState(self, newState, reason=None):
     # print "%s._setState(newState=%s, reason=%s)" % (self, newState, reason)
     TCPConnection._setState(self, newState=newState, reason=reason)
     if self._state == self.Authorizing and not self._didStartAuth:
         self._didStartAuth = True
         self.writeLine("1 auth knockKnock")
Exemple #14
0
    import sys
    import socket as ss
    import threading
    import time
    from UDPConnection import UDPConnection
    from TCPConnection import TCPConnection
    from AudioClient import AudioSocketClient
    from VideoClient import VideoSocket
    from time import gmtime, strftime
    from playsound import playsound

    app = QtWidgets.QApplication(sys.argv)
    application = MainWindow()
    application.show()

    TCP_socket = TCPConnection(application.signal.new_message)
    application.set_TCP_socket(TCP_socket)

    # audio_socket = AudioSocketClient()
    # application.set_audio_socket(audio_socket)

    application.ui.Btn_Find_Server.clicked.connect(application.find_server)
    application.ui.Btn_Log_In.clicked.connect(application.log_in)
    application.ui.Btn_Send_Message.clicked.connect(
        application.prepare_and_send_message)
    application.ui.Btn_Log_Out.clicked.connect(application.log_out)
    application.ui.Btn_History_Request.clicked.connect(
        application.history_request)
    application.ui.Btn_Call.clicked.connect(
        application.call_recipient_button_click)
    application.ui.Btn_Mute_Mic.clicked.connect(
Exemple #15
0
 def setUp(self):
     self.tcp = TCPConnection()
Exemple #16
0
 def setUp(self):
     self.tcp = TCPConnection()
Exemple #17
0
    from UDPConnection import UDPConnection
    from TCPConnection import TCPConnection
    from AudioServer import AudioSocketServer

    HOST = socket.gethostbyname(socket.gethostname())
    PORT = 50007
    LISTEN_ALL_HOST = '0.0.0.0'

    app = QtWidgets.QApplication(sys.argv)
    application = MainWindow()
    application.show()

    UDP_socket = UDPConnection(HOST, PORT)
    UDP_socket.setsockopt_reuseaddr()
    UDP_socket.bind(LISTEN_ALL_HOST, PORT)
    UDP_socket.send_address_to_sender()
    UDP_socket.start_UDP_receiving()

    TCP_socket = TCPConnection(application.signal.new_mes)
    TCP_socket.setsockopt_reuseaddr()
    TCP_socket.bind(HOST, PORT)
    TCP_socket.listen(10)
    TCP_socket.set_server_socket()

    application.set_socket(TCP_socket)
    application.start_threading()

    audio_socket = AudioSocketServer(HOST, PORT + 1)

    sys.exit(app.exec())
Exemple #18
0
 def _setState(self, newState, reason=None):
     # print "%s._setState(newState=%s, reason=%s)" % (self, newState, reason)
     TCPConnection._setState(self, newState=newState, reason=reason)
     if self._state == self.Authorizing and not self._didStartAuth:
         self._didStartAuth = True
         self.writeLine("1 auth knockKnock")