Esempio n. 1
0
def server(interface, port):
    server_stack = PyStack(interface)  # Create a stack
    print '1'

    server_app = TCPApplication()  # Create a TCPApplication

    server_stack.register_tcp_application(server_app)
    server_stack.run(
        doreactor=False
    )  # Run the stack to start listening using a thread to make it non-blocking

    server_app.bind(port, server_app, False)

    print '2'
    server_app.listen(3)  # the maximum tcp clients to establish connections
    print '3'
    flow_one = server_app.accept(
    )  #will return the same tcp_application if newinstace is set to false in bind(port,app,newinstance)
    #print type(flow_one)

    print 'accept client request'

    while True:
        time.sleep(1)
        #flow_one.send_packet('ok')
        data = flow_one.fetch_data()
        if data != None:
            print data
            kwargs["IP"]["flags"] = 2

            if t1 or t2:
                t1 = t1 if t1 else 0
                import time
                #t1 = time.time()
                t2 = t2 if t2 else 0
                #t2 = 0
                if kwargs["TCP"].has_key("options"):
                    kwargs["TCP"]["options"].append(("Timestamp", (t1, t2)))
                else:
                    kwargs["TCP"]["options"] = [("Timestamp", (t1, t2))]

            if res:
                kwargs["IP"]["flags"] = 2

        return packet, kwargs


if __name__ == "__main__":
    stack = PyStack()

    steganoapp = SteganoApplication()
    server = TCPApplication()
    stack.register_tcp_application(server)

    server.bind(7777, steganoapp, True)
    server.listen(5)

    stack.run(doreactor=True)  #stack.stop() called when Ctrl+C
            if t1 or t2:
                t1 = t1 if t1 else 0
                import time
                #t1 = time.time()
                t2 = t2 if t2 else 0
                #t2 = 0
                if kwargs["TCP"].has_key("options"):
                    kwargs["TCP"]["options"].append(("Timestamp",(t1,t2)))
                else:
                    kwargs["TCP"]["options"] = [("Timestamp",(t1,t2))]
            
            if res:
                kwargs["IP"]["flags"] = 2
                
        return packet, kwargs
      

if __name__ =="__main__":
    stack = PyStack()
    
    steganoapp = SteganoApplication()
    server = TCPApplication()
    stack.register_tcp_application(server)
    
    server.bind(7777, steganoapp, True)
    server.listen(5)
    
    stack.run(doreactor=True) #stack.stop() called when Ctrl+C