Module Expr Str ImportFrom alias identifier ImportFrom alias ImportFrom alias ImportFrom alias alias alias ImportFrom alias alias alias ImportFrom alias alias Assign NameStore Str Assign NameStore Str Assign NameStore BinOpAdd Str NameLoad FunctionDef arguments args defaults body Assign NameStore Call NameLoad keyword NameLoad keyword NameLoad Expr Call AttributeLoad NameLoad attr Str Str keyword Str keyword NameLoad keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str Str keyword Str keyword NameLoad keyword Str keyword Str Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr If CompareLt Call NameLoad NameLoad Num body Expr Call AttributeLoad NameLoad attr Raise Call NameLoad Num Return TupleLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index Num Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index NameLoad Expr Call AttributeLoad NameLoad attr Call NameLoad NameLoad Str Delete SubscriptDel AttributeLoad NameLoad attr Index NameLoad Delete SubscriptDel AttributeLoad NameLoad attr Index NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Expr Call AttributeLoad NameLoad attr Call NameLoad keyword AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index SubscriptLoad AttributeLoad NameLoad attr Index Num Expr Call AttributeLoad NameLoad attr Call NameLoad NameLoad NameLoad Str decorator_list ClassDef bases NameLoad body FunctionDef arguments args NameParam NameParam NameParam NameParam defaults NameLoad body Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Call NameLoad Assign AttributeStore NameLoad attr Call NameLoad Assign NameStore Call NameLoad AttributeLoad NameLoad attr keyword AttributeLoad NameLoad attr keyword Str Expr Call AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults body Expr Str Assign NameStore Num Assign NameStore Call NameLoad Assign NameStore Call NameLoad NameLoad keyword NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr Call Call NameLoad Str keyword NameLoad NameLoad Expr Call AttributeLoad NameLoad attr Call Call NameLoad Str keyword NameLoad NameLoad Expr Call AttributeLoad NameLoad attr Call Call NameLoad Str keyword NameLoad NameLoad Assign SubscriptStore AttributeLoad NameLoad attr Index NameLoad NameLoad Assign SubscriptStore AttributeLoad NameLoad attr Index AttributeLoad NameLoad attr NameLoad decorator_list Call NameLoad Str keyword Str FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index NameLoad Expr Call AttributeLoad NameLoad attr Call NameLoad NameLoad AttributeLoad NameLoad attr decorator_list Call NameLoad Str keyword Str decorator_list FunctionDef arguments args NameParam defaults body If CompareIn Str NameLoad body Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr Str Assign NameStore Call NameLoad NameLoad Return TupleLoad NameLoad NameLoad Return NameLoad decorator_list FunctionDef arguments args defaults body Assign TupleStore NameStore NameStore Call NameLoad Assign NameStore Call NameLoad SubscriptLoad NameLoad Index Num Assign NameStore Call NameLoad SubscriptLoad NameLoad Index Num If CompareIsNot Call NameLoad NameLoad NameLoad body Print Str Raise Call NameLoad Num If CompareIsNot Call NameLoad NameLoad NameLoad body Print Str Raise Call NameLoad Num Assign NameStore Call NameLoad NameLoad NameLoad If AttributeLoad NameLoad attr body Expr Call AttributeLoad Call NameLoad Str attr NameLoad If AttributeLoad NameLoad attr body Expr Call AttributeLoad Call NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr decorator_list If CompareEq NameLoad Str body Expr Call NameLoad
N/A N/A A Port Forwarding Example

This example demonstrates slightly more complex features and behaviors
implementing a TCP/UDP Port Forwarder of network traffic. This can be used
as a simple tool to forward traffic from one port to another.

Example:

    ./portforward.py 0.0.0.0:2222 127.0.0.1:22

This example also has support for daemonizing the process into the background.
 uuid uuid4 uuid optparse OptionParser circuits.app Daemon circuits handler Component Debugger circuits.net.events close connect write circuits.net.sockets TCPClient TCPServer N/A __version__ 0.2 N/A USAGE %prog [options] <srcaddr:srcport> <destaddr:destport> N/A VERSION N/A %prog v __version__ parse_options N/A N/A N/A N/A N/A parser N/A OptionParser usage USAGE version VERSION N/A N/A N/A parser add_option -d --daemon action store_true default False dest daemon help Enable daemon mode (fork into the background) N/A N/A N/A parser add_option --debug action store_true default False dest debug help Enable debug mode (verbose event output) N/A N/A opts args N/A N/A parser parse_args N/A N/A N/A len args 2 N/A N/A N/A N/A parser print_help N/A N/A SystemExit 1 N/A N/A opts args N/A _on_target_disconnected N/A N/A self event N/A N/A N/A Disconnected Event Handler

    This unbound function will be later added as an event handler to a
    dynamically created and registered client instance and used to process
    Disconnected events of a connected client.
     N/A channel N/A N/A event channels N/A 0 N/A sock N/A N/A self _sockets N/A channel N/A N/A N/A self fire N/A close sock source N/A N/A N/A self _sockets N/A channel N/A N/A N/A self _clients N/A sock N/A _on_target_ready N/A N/A self component N/A N/A N/A Ready Event Handler

    This unbound function will be later added as an event handler to a
    dynamically created and registered client instance and used to process
    Ready events of a registered client.
     N/A N/A N/A self fire N/A connect secure N/A self _secure N/A self _target N/A component channel N/A _on_target_read N/A N/A self event data N/A N/A N/A Read Event Handler

    This unbound function will be later added as an event handler to a
    dynamically created and registered client instance and used to process
    Read events of a connected client.
     N/A sock N/A N/A self _sockets N/A N/A N/A event channels N/A 0 N/A N/A N/A self fire N/A write sock data source N/A PortForwarder N/A Component N/A init N/A N/A self source target secure N/A False N/A N/A N/A self _source source N/A N/A self _target target N/A N/A self _secure secure N/A N/A self _clients N/A dict N/A N/A self _sockets N/A dict N/A server N/A TCPServer N/A self _source secure N/A self _secure channel source N/A N/A N/A server register self N/A _on_source_connect N/A N/A self sock host port N/A N/A N/A Explicitly defined connect Event Handler

        This evens is triggered by the underlying TCPServer Component when
        a new client connection has been made.

        Here we dynamically create a Client instance, registere it and add
        custom event handlers to handle the events of the newly created
        client. The client is registered with a unique channel per connection.
         N/A bind 0 N/A channel N/A uuid N/A client N/A TCPClient bind channel channel N/A N/A N/A client register self N/A N/A N/A self addHandler N/A N/A handler disconnected channel channel _on_target_disconnected N/A N/A N/A self addHandler N/A N/A handler ready channel channel _on_target_ready N/A N/A N/A self addHandler N/A N/A handler read channel channel _on_target_read N/A N/A N/A self _clients N/A sock client N/A N/A N/A self _sockets N/A N/A client channel sock N/A N/A handler connect channel source _on_source_read N/A N/A self sock data N/A N/A N/A Explicitly defined Read Event Handler

        This evens is triggered by the underlying TCPServer Component when
        a connected client has some data ready to be processed.

        Here we simply fire a cooresponding write event to the cooresponding
        matching client which we lookup using the socket object as the key
        to determinte the unique id.
         N/A client N/A N/A self _clients N/A sock N/A N/A N/A self fire N/A write data N/A client channel N/A N/A handler read channel source N/A sanitize N/A N/A s N/A N/A N/A N/A : s N/A N/A N/A address port N/A N/A s split : N/A port N/A int port N/A N/A address port N/A s N/A main N/A N/A N/A N/A N/A N/A opts args N/A parse_options N/A source N/A sanitize N/A args N/A 0 N/A target N/A sanitize N/A args N/A 1 N/A N/A N/A type source tuple N/A N/A ERROR: source address must specify port (address:port) N/A N/A SystemExit -1 N/A N/A N/A type target tuple N/A N/A ERROR: target address must specify port (address:port) N/A N/A SystemExit -1 N/A system N/A PortForwarder source target N/A N/A opts daemon N/A N/A N/A N/A N/A Daemon portforward.pid register system N/A N/A opts debug N/A N/A N/A N/A N/A Debugger register system N/A N/A N/A system run N/A N/A N/A __name__ __main__ N/A N/A N/A main